Articles
Kafka Streams Interview Questions: State Stores, Repartitioning, and Recovery
Prepare for Kafka Streams interviews with worked examples of state stores, repartitioning, recovery estimates, joins, exactly-once scope, and testing.
Kafka Streams interview questions test whether you can connect an application's code to the keys, partitions, and durable state that make its results correct. Knowing what a broker does is useful, but it does not explain why a customer total is wrong after a key change or slow to recover after a restart.
The direct answer: identify the record key at every stateful boundary, explain where each task stores state, distinguish repartition topics from changelogs, and define the recovery and delivery guarantees. Use those facts to predict behavior under skew, failure, and late arrival.
The examples below are original design exercises grounded in Apache Kafka's version 4.2 documentation, not claims about a company's question bank.
Where does Kafka Streams actually run?
Kafka Streams is an application library. Your service runs its processing topology, while Kafka provides the topics and coordination on which that processing depends. There is no separate Streams cluster scheduler that automatically supplies your application's machines.
Apache's architecture documentation organizes processing into tasks connected to input partitions. Stream threads execute those tasks within application instances. A stateful task owns local state associated with its assigned work; adding another process changes work placement rather than creating another independent copy of the business result.
For an interview, draw three distinct things: application instances, logical tasks, and Kafka topics. Put a local store beside its task. Then ask what happens if an instance disappears. The task must run elsewhere and regain usable state, while its durable input remains in Kafka.
This drawing immediately exposes a weak proposal such as "add ten pods to make the one hot customer faster." Placement and key-level work distribution are different problems.
Is the input a stream of events or a table of updates?
The DSL distinguishes a KStream record stream from a KTable changelog interpretation. In an event stream, two records with key A can be two purchases. In a table, a later value for A represents an updated value for that key.
Suppose the input is A/12 followed by A/8. If these are purchases, the intended total is 20. If they are successive account balances, adding them is a semantic error: the latest balance is 8. Ask what each record means before choosing an operator.
Use this distinction when discussing deletion and missing data as well. A table tombstone is not just an ordinary purchase with an unknown amount. Null-key and null-value behavior depends on the operator, so avoid promising that every operation treats them identically.
In a design answer, name the source contract explicitly: immutable order events, corrected order snapshots, or customer profile updates. Two topics with identical schemas can require different processing because their records mean different things.
When does a key change require repartitioning?
Consider orders keyed by order ID: o1 belongs to A for 12, o2 belongs to B for 7, and o3 belongs to A for 8. A customer aggregation must bring both A records to the same logical processing location. Keeping the order key would count or sum by order instead.
A key-changing transformation followed by a key-based DSL operation can cause a repartition boundary. The intermediate topic redistributes records according to the new key. The important point is not that every key change immediately writes to Kafka; the topology's downstream requirements determine the boundary.
Trace the example as a proposed design: parse each order, assign its customer key, group on that key, and aggregate the amount. The expected final values are A/20 and B/7. Test those values with order IDs deliberately spread across source partitions.
Inspect the described topology rather than guessing which internal topics exist. Explicit naming and known serializers make that inspection much easier during a review or incident.
How are repartition topics different from changelogs?
A repartition topic moves records into the right key distribution for downstream processing. A changelog records state changes so a task's local store can be reconstructed. They solve different problems even when both appear as internal Kafka topics.
| Artifact | Question it answers | Example in the order exercise |
|---|---|---|
| Input topic | What events entered the application? | Orders o1, o2, o3 |
| Repartition topic | Which task should handle this customer? | Both A orders routed by A |
| Local store | What aggregate is available here now? | A has total 20 |
| Changelog | How can that state be restored? | Durable updates for the aggregate |
Do not propose deleting an internal topic simply because it looks temporary. First identify its role, retention configuration, and relationship to the deployed topology. Removing a recovery source can turn a routine replacement into an unrecoverable or expensive rebuild.
For an interview follow-up, explain which data could be reconstructed from original events and how long those events remain available. "We can replay" requires an actual retained history and compatible code.
What belongs in a state store?
A state store holds the working information needed by stateful processing: an aggregate, a lookup representation, or records retained for a windowed operation. Its design should follow the query and update contract, not a generic preference for caching everything.
For customer totals, a compact entry per customer may be enough. For deduplicating order IDs, you additionally need a remembered set or equivalent structure with an explicit retention horizon. A total alone cannot tell whether order o1 was already included.
Ask about cardinality and lifetime. One million customers with bounded aggregate records is a different storage problem from retaining every event forever. Estimate the state using your assumed record size, then include indexing and storage overhead as unknowns to measure.
Also define serialization compatibility. A restart with a new value schema can fail while restoring historical state even if new input events deserialize successfully. Review state evolution alongside source and output schema changes; recovery exercises should include data written by the previous application version.
How does recovery work after losing an instance?
Apache documents automatic task reassignment and state restoration. A replacement task can reuse suitable local state when available or reconstruct state from its recovery source. Standby replicas can reduce the amount of restoration work, but they consume resources and do not eliminate every failover delay.
For an illustrative estimate, suppose 6 GB of changelog remains to restore and sustained replay is 50 MB per second, using decimal units. The arithmetic gives 120 seconds. Add an assumed 20 seconds for assignment and startup and the planning estimate becomes 140 seconds.
That number is not a product guarantee. Disk throughput, decompression, network contention, concurrent restores, and continued changelog growth may change the result. State your assumptions and ask for measured restore metrics before promising a recovery objective.
A useful failure drill removes local storage, not just the process. A quick restart on a warm disk tests a different condition from replacing a host. Record when processing resumes and when lag returns to its normal range.
What does exactly-once processing cover?
The configured processing guarantee determines how Kafka Streams coordinates consumed offsets, state changes, and Kafka output. In the documented exactly-once mode, the consistency boundary is Kafka processing, not every external action your callback might perform.
Suppose processing an order also sends an email. A crash after the email is sent but before the relevant Kafka transaction completes can lead to another execution and another email. A Kafka transaction cannot retroactively unsend that external message.
A defensible proposal emits an email command to Kafka and gives the downstream sender an idempotency policy keyed by a stable business identifier. Then discuss the sender's own failure cases. This moves the external effect into an explicit delivery design rather than hiding it behind an exactly-once label.
Ask whether repeated source events are legitimate separate purchases or duplicates. Processing each input record once does not automatically deduplicate two distinct input records that represent the same business event. Business identity remains part of the application contract.
Why can a join be incomplete even when both topics have data?
A join needs compatible key semantics, appropriate partitioning, and the correct temporal relationship. Seeing matching text in two topic dumps does not establish that the topology processed those records together under its join rules.
Imagine purchase A arrives before customer A's profile update. Decide whether the result may initially lack enrichment, whether a later profile change should update previous results, or whether the business requires a bounded wait. Those are different products, not interchangeable join implementations.
For a windowed event join, make time concrete. One event has timestamp 10:00 and another 10:04. A hypothetical two-minute matching interval will not match them merely because both were ingested at 10:05. Specify timestamps and the operator's interval before predicting output.
Use explicit tests for arrival order, absent lookup rows, repeated updates, and records outside the accepted interval. Avoid claiming universal SQL equivalence: a continuously evolving stream has observable timing and update behavior that a static relational example can hide.
How should you reason about late records?
Separate event timestamps, processing time, stream-time advancement, and the application's lateness policy. A wall-clock delay alone does not tell you whether a record remains eligible for a particular window.
Write a test scenario with a ten-minute window and an explicitly configured grace period. Feed records with controlled timestamps, then advance the relevant stream time past the acceptance boundary. Assert the accepted aggregate and the behavior for a subsequent late record.
Do not present grace as storage retention or as a promise that every source will wait for a slow partition forever. These settings and progress rules serve different purposes. Explain which one defines admissible lateness and which one controls how long materialized data remains available.
For a business discussion, ask whether late corrections should be rejected, routed for reconciliation, or handled in a separate correction path. A dashboard count and a financial settlement pipeline may need different policies even if they use the same window size.
Why did adding threads fail to fix lag?
Use a simple single-source topology with six input partitions and six tasks. Two instances with two stream threads each provide four threads; those threads can share the six tasks, for example with task counts 2, 1, 2, and 1. Six threads can give each task a thread. More threads do not create more source partitions.
Now suppose one customer generates most records. That customer's key still concentrates work. Diagnose per-partition rates and processing time before adding machines. A slow external call inside processing, expensive serialization, or a storage bottleneck can also dominate.
Salting a key is not a free repair. Splitting A across subkeys requires a second combination step and may complicate ordering or exact deduplication. First determine whether the computation can be decomposed while preserving the required result.
The strongest answer names the constrained resource and proposes a measurement: input distribution, task processing latency, store performance, or restoration load. "Increase concurrency" without that evidence is only a guess.
What should your test and rollout demonstrate?
Use the official topology test tools for deterministic records, timestamps, expected output, and store contents. For the order example, assert A/20 and B/7, then add a duplicate order, an invalid amount, and a new customer. State the intended behavior for each before writing assertions.
| Test layer | Useful evidence | What it does not establish alone |
|---|---|---|
| Topology test | Transformation and state logic | Real broker failover |
| Multi-instance integration | Assignment and recovery behavior | Production capacity |
| Representative load test | Throughput and skew sensitivity | Every future traffic pattern |
Before rollout, compare the old and new topology, application identity, internal topic names, and state schemas. Preserve a rollback or rebuild plan that matches retained data. Changing an application identifier can change the application's processing identity and its relationship to existing state.
Practice the full explanation using one concrete failure: an instance disappears immediately after processing A's second purchase. Describe the recovery source, observable output guarantee, restore estimate, and external effects. That answer shows how the pieces fit together without depending on memorized configuration lists.
Sources and Further Reading
- Apache Kafka Streams architecture covers tasks, threads, local state, and recovery.
- Streams DSL documents streams, tables, joins, repartitioning, and windows.
- Streams configuration defines application identity, standby replicas, and processing guarantees.
- Interactive queries explains querying distributed application state.
- Testing Streams applications describes topology testing tools and their use.
Sources reviewed September 24, 2026. These references deliberately target Kafka 4.2, which Apache now labels an older version; confirm your deployed version before applying configuration details.