Stream Processing and Event Streaming Questions
Building on event-streaming platforms: Kafka and message queues, event sourcing, partitioning, consumer groups, exactly-once vs at-least-once delivery, and windowing. Covers handling late and out-of-order events, watermarks, and stateful stream operators. The core skill for real-time data engineering.
What factors should drive partition-key selection for a topic (cardinality, hot-key avoidance, the ordering a downstream aggregation actually needs)? Walk through the trade-offs for a concrete topic with a natural user or entity ID.
Sample Answer
Direct answer
Partition-key choice is a balance between cardinality (enough distinct values to spread load evenly across partitions), hot-key avoidance (no single value dominating traffic), and preserving whatever ordering guarantee your downstream processing actually needs, which usually means keying on the entity whose events must stay in relative order.
Structured elaboration
Too low a key cardinality (or one value that's disproportionately common) concentrates traffic onto a small number of partitions regardless of how many partitions the topic has, defeating the purpose of partitioning for parallelism. The key also directly determines what ordering guarantee a consumer sees: events sharing a key are guaranteed to arrive in production order relative to each other, while events with different keys have no ordering relationship, so the key should be chosen to match whatever entity actually needs that guarantee (commonly a user ID, an account ID, or an order ID), not chosen purely for even load distribution if that conflicts with a real ordering requirement.
Worked example
For an orders topic needing per-order ordering (an order's create, update, and cancel events must be processed in that exact sequence), keying by order_id guarantees this at the cost of no guarantee across different orders, which is fine since nothing needs that. If a small number of very large customers generate a disproportionate share of all orders (a common real-world skew), keying purely by order_id still spreads load reasonably evenly since orders themselves are numerous and roughly uniform, whereas keying instead by customer_id for the same use case would concentrate a large customer's high order volume onto whichever partition their customer ID hashes to, a genuine hot-partition risk.
Trade-offs and pitfalls
A key chosen purely for even distribution, ignoring the actual ordering requirement, will pass every load test cleanly while silently violating a correctness requirement nobody tested for (out-of-order processing for a given entity) until it causes a real, hard-to-reproduce bug. Conversely, a key chosen purely for correctness without checking its cardinality and skew can pass correctness review and then fail under load the first time one key's traffic dominates; both properties need to be checked, not just one.
A small number of heavy keys are producing most of a topic's traffic, creating hot partitions and outage-like symptoms. Describe how you'd detect this and remediate it without breaking the per-key ordering guarantee downstream consumers rely on.
Sample Answer
Direct answer
Detecting and remediating a hot partition without breaking ordering means either splitting the hot key into several sub-keys that route to different partitions (salting), or, if that's not possible without breaking a real business ordering requirement for that key, isolating the hot key onto its own dedicated partition rather than force-spreading it.
Structured elaboration
Detection is straightforward: monitor per-partition throughput and identify partitions receiving disproportionately more traffic than the average, then trace that imbalance back to specific keys mapping to those partitions. Remediation has two genuinely different shapes depending on whether the hot key's events actually need strict relative ordering: if they don't (each event for that key can be processed independently, in any order, without breaking correctness), salting the key into sub-keys spreads its load across multiple partitions cleanly. If the key's events DO need strict ordering (a common case for high-volume, high-value keys, like a major customer's order stream), salting isn't safe, since it would let events for that same key be processed in parallel, out of order, across sub-keys, so the remediation instead is to give that specific hot key its own dedicated, appropriately-provisioned partition, isolating its load rather than attempting to spread it.
Worked example
A topic where 10% of partitions receive 90% of traffic due to a handful of very large, heavy-user keys: for keys where per-key ordering genuinely doesn't matter (say, individual page-view events with no cross-event dependency), salting each hot key into several sub-keys spreads that key's traffic across multiple partitions immediately. For a hot key representing a major customer's order stream, where per-order-key ordering genuinely matters for correctness, the fix instead routes that specific customer's key to a dedicated partition sized and provisioned for its actual (much higher) throughput, leaving the rest of the topic's more evenly-distributed keys on the regular partition scheme.
Trade-offs and pitfalls
Salting a key that genuinely needs ordering silently breaks correctness while looking, from a load-distribution metric alone, like a successful fix; the ordering requirement has to be checked first, not assumed away because the throughput problem is otherwise straightforward to solve. Dedicating a partition to one hot key is a manual, ongoing operational overhead (someone has to notice when a NEW key becomes hot and repeat the process) rather than a fully automatic, self-scaling solution.
Discuss the trade-offs between a single global watermark and per-key or per-partition watermarks. Give an example where each is preferable, and what correctness risk the coarser choice introduces.
Sample Answer
Direct answer
A single global watermark is simpler but only as tight as your slowest partition or key, while per-key or per-partition watermarks let fast-moving keys close their windows promptly without waiting on a slow one, at the cost of tracking and managing many more watermark states.
Structured elaboration
A global watermark takes the minimum (most conservative) progress across every partition feeding the job; if one partition is genuinely behind (a slow upstream source, a temporarily struggling broker), every window across every key waits on that one laggard, even keys whose own data has been fully caught up for a while. Per-key or per-partition watermarks decouple this: each partition's (or key's) windows close based on its own observed progress, so a healthy partition isn't held hostage by an unrelated struggling one, at the cost of the processor needing to track and reconcile many independent watermark states instead of one.
Worked example
A multi-region ingestion pipeline where one region's network link is degraded and running 10 minutes behind: with a single global watermark, every other region's windows also wait those same 10 minutes before closing, even though their own data arrived on time. With per-partition watermarks keyed to region, the healthy regions' windows close promptly on their own timeline, and only the degraded region's windows lag, correctly isolating the problem to where it actually originates rather than spreading the delay to unaffected data.
Trade-offs and pitfalls
The correctness risk of a single global watermark is exactly the coarseness described above: a genuinely small, contained problem in one partition becomes a system-wide latency problem for everyone. The correctness risk of per-key watermarks going the other way is that a downstream consumer expecting one unified, globally-ordered stream of window closes now sees closes arriving at different times for different keys, which needs to be an accepted and understood property of the output, not a surprise; a naive downstream join or comparison across keys assuming synchronized closes can produce subtly wrong results if it doesn't account for this.
Design a deduplication strategy for a pipeline running under at-least-once delivery, where events carry an ID and timestamp but some IDs may collide or be missing. Cover the dedup-store choice, a time-to-live for the dedup window, and how you'd bound memory while still catching duplicates that arrive far apart.
Sample Answer
Direct answer
Design the dedup strategy around a bounded, time-to-live-backed store keyed by each event's own ID (or a composite key when no single field is globally unique), sized against how far apart in time a real duplicate can plausibly arrive, so you catch genuine duplicates without holding every key forever.
Structured elaboration
The dedup store's job is a simple membership check: has this event's key been seen recently? The design choices that actually matter are: what to use as the key when IDs can collide or be entirely missing (fall back to a composite of fields that are, in combination, effectively unique, such as source plus a natural key plus a timestamp bucket); how long to remember a key (a TTL keyed to event time, not wall-clock arrival time, so an out-of-order but still-recent duplicate is still caught); and what backing store to use (an in-memory or embedded key-value store with TTL support for the hot path, backed by something durable if the dedup window needs to survive a restart).
Worked example
For a pipeline expecting duplicates to arrive within roughly an hour of the original (retries, replays, or upstream at-least-once redelivery), a TTL-bounded store keyed by event ID with a 1-hour window catches the overwhelming majority of real duplicates while bounding memory to roughly (events per hour) x (key size), rather than growing forever. For events with colliding or missing IDs, falling back to a composite key like (source_system, natural_business_key, minute_bucket) restores effective uniqueness without relying on a field that isn't trustworthy.
Trade-offs and pitfalls
A TTL set too short lets a slow-arriving duplicate (say, a retry that happens to take 90 minutes instead of the expected hour) through as if it were new, which is a silent correctness gap rather than a loud failure; a TTL set too long grows memory unnecessarily on a high-cardinality key space, since most legitimate duplicates arrive much sooner than the worst case you're defending against. This is fundamentally a probabilistic trade-off tuned against your actual observed duplicate-arrival distribution, not something you can set correctly from first principles alone; it should be revisited once you have real production data on how late duplicates actually arrive.
Design the operational controls for a multi-tenant streaming platform (shared Kafka cluster and stream-processing jobs) used by many teams: resource quotas, access controls, network isolation, and how you'd prevent one noisy tenant from degrading others.
Sample Answer
Direct answer
Operating a multi-tenant streaming platform means enforcing per-tenant resource quotas, isolating access via authentication and authorization, and building in guardrails so one tenant's misbehaving workload can't degrade everyone else's throughput or latency.
Structured elaboration
Resource quotas (throughput quotas on produce/fetch requests, storage quotas per topic or tenant) are the primary lever against noisy neighbors: without them, one tenant pushing an unexpected volume spike can consume shared broker bandwidth or CPU that every other tenant depends on. Access controls (ACLs scoping which principals can produce or consume from which topics, network-level isolation for genuinely sensitive tenants) prevent one team from accidentally (or maliciously) reading or writing another's data. For stateful stream-processing jobs specifically (Flink or Kafka Streams jobs run on shared compute, often on Kubernetes), the same isolation problem shows up as noisy-neighbor CPU/memory contention between jobs on the same cluster, addressed with resource requests/limits per job, dedicated node pools for the largest tenants, and safe rolling-upgrade paths that don't require taking the whole shared cluster down.
Worked example
Concretely, a shared cluster serving five teams would set a per-tenant produce-byte-rate quota (so no single tenant's traffic spike starves the others), ACLs scoping each team's service accounts to only their own topic prefix, and, for the Kubernetes-hosted stream-processing jobs layer, per-job resource requests/limits plus pod anti-affinity rules so two large jobs don't land on the same node and compete for the same CPU. A safe upgrade path (rolling one node at a time, verifying job health before proceeding) avoids a platform-wide outage when applying a change that affects every tenant's jobs.
Trade-offs and pitfalls
Too-strict quotas can throttle a legitimate tenant during an expected traffic spike (a marketing campaign, a seasonal peak) unless quotas are reviewed and adjusted proactively rather than reactively. The common operational mistake is treating multi-tenancy as purely an access-control problem and skipping resource quotas entirely, which leaves the platform vulnerable to exactly the noisy-neighbor scenario multi-tenancy is supposed to guard against; ACLs stop the wrong people from touching the wrong data, but they don't stop the right person's workload from starving everyone else.
Unlock Full Question Bank
Get access to all Stream Processing and Event Streaming interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.