Quick revision
The short answer
Nothing is lost. KTable operations write through a record cache, 10 MB per instance by default, which merges consecutive updates to the same key and forwards only the latest value when the cache is flushed on commit, every 30 seconds with at-least-once processing. A hot key therefore emits about one update per commit, while TopologyTestDriver flushes after every record. To see every update, disable caching for that store; to emit less, tune the cache, the commit interval or use suppress(); and a team that needs every change should read the underlying stream.
What to remember
In this answer, we saw that a KTable's output means latest value per key, and that Streams uses a record cache, flushed on every commit, to merge updates to the same key. With at-least-once processing that means about one output per hot key every 30 seconds, while TopologyTestDriver flushes after every record. Nothing is lost. We can disable caching per store to forward every update, emit less with a larger cache, longer commits or suppress(), and a team that needs every change should consume the stream rather than the table.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Nothing is lost. KTable operations write through a record cache, 10 MB per instance by default, which merges consecutive updates to the same key and forwards only the latest value when the cache is flushed on commit, every 30 seconds with at-least-once processing. A hot key therefore emits about one update per commit, while TopologyTestDriver flushes after every record. To see every update, disable caching for that store; to emit less, tune the cache, the commit interval or use suppress(); and a team that needs every change should read the underlying stream.
Why this question is asked
This report comes up often: tests show one output per input, production shows far fewer, and someone concludes that Kafka Streams drops data. Interviewers ask it because the answer separates people who know how KTables really emit results from people who only know the API. In this answer, we will recap what a KTable's output means, look at the record cache and when it flushes, see why the test driver behaves differently, go through the ways to control the output, and explain what to tell the downstream team.
1A Quick Recap of a KTable's Output
A KTable holds the latest value per key. When we call toStream() on it, we get its updates: each record says that the value for this key is now this. Downstream, the correct reading of such a topic is latest value per key. Two records for product 12, count 41 and count 42, do not mean two events; the second simply replaces the first.
That meaning gives Kafka Streams freedom: if it knows that count 42 replaces count 41 before either has been sent, it can send only 42 and the result is still correct.
2The Record Cache Between the Store and Downstream
KTable state stores sit behind a record cache. When an update arrives, Streams writes it into the cache rather than straight to the store, the changelog and downstream. If another update for the same key arrives before the cache is flushed, it overwrites the cached entry. The cache size is statestore.cache.max.bytes (called cache.max.bytes.buffering in older versions), 10 MB per application instance by default, shared among its threads.
The cache is flushed on every commit, and Streams commits every commit.interval.ms: 30,000 ms with at-least-once processing and 100 ms with exactly-once. An entry can also be evicted earlier if the cache fills up. For our product receiving 200 updates a minute, about 100 updates arrive between two commits, and they collapse into one output record every 30 seconds. The final value is identical; only the intermediate values are compacted away.
7 messages in order. Play them, or step through them one at a time.
The cache merges updates to one key between commits; nothing downstream sees 41..139.
3Why the Tests Showed Every Update
TopologyTestDriver processes each piped record and then commits, which flushes the cache after every single input. So in tests every update appears in the output, and in production they are merged. Tests that assert on the intermediate values, such as expecting the output list to contain 1, 2, 3 and 4, are testing behaviour that production will not reproduce. A better test asserts on the latest value per key, for example by reading the output into a map, or reads the state store directly.
4Controlling How Much Is Emitted
If the downstream really needs every intermediate update, we can turn caching off for this one store, or for the whole application by setting the cache size to 0. Both increase output volume and changelog writes, roughly 200 records a minute for this product instead of 2, so we do it only where needed.
| Option | Output for a hot key | Cost |
|---|---|---|
| Default cache, at-least-once | About 1 per 30 s commit | Lowest output volume |
withCachingDisabled() | Every update | More output and changelog writes |
| exactly-once (100 ms commits) | Up to about 10 per second | Transaction overhead |
suppress(untilTimeLimit) | At most 1 per time limit | Buffer memory; uses stream time |
In the other direction, a larger cache and a longer commit interval reduce output further. For explicit rate limiting that does not depend on commits, suppress() with Suppressed.untilTimeLimit holds updates per key and emits the latest after a time limit; for windowed aggregations, Suppressed.untilWindowCloses emits one final result per window.
5What to Tell the Downstream Team
The team should treat the output topic as a table: latest value per key, ideally compacted. If what they really want is every change event, for example to audit each update, they should not read a table's output at all; they should consume the underlying KStream or input topic, where every record is preserved. Choosing the right source is better than turning caching off to make a table imitate a stream.
6Follow-up questions
When would you use suppress(Suppressed.untilTimeLimit(...)) here?
When downstream wants a predictable maximum rate per key that does not change if someone tunes the commit interval or turns on exactly-once. For example suppress(Suppressed.untilTimeLimit(Duration.ofSeconds(10), BufferConfig.maxRecords(100_000).emitEarlyWhenFull())) emits each product's latest count at most every 10 seconds of stream time. Note that the limit is measured in stream time, driven by record timestamps, so a key that stops receiving records may wait until newer records arrive on that partition.
Does the cache affect the changelog too?
Yes. Merged updates are written to the changelog once per flush, which is one of the main reasons the cache exists: it can cut changelog traffic by orders of magnitude for hot keys.
Is the cache the same as RocksDB's block cache?
No. The record cache is a Kafka Streams cache in the JVM heap that deduplicates updates before they reach the store; RocksDB's block cache is off-heap and speeds up reads of data already in the store.
7Conclusion
In this answer, we saw that a KTable's output means latest value per key, and that Streams uses a record cache, flushed on every commit, to merge updates to the same key. With at-least-once processing that means about one output per hot key every 30 seconds, while TopologyTestDriver flushes after every record. Nothing is lost. We can disable caching per store to forward every update, emit less with a larger cache, longer commits or suppress(), and a team that needs every change should consume the stream rather than the table.
Open with
Nothing is being lost; it is the KTable record cache. KTable state stores write through a cache, statestore.cache.max.bytes, formerly cache.max.bytes.buffering, 10 MB per instance by default. Consecutive updates to the same key overwrite each other in the cache, and only the latest value is forwarded downstream and written to the changelog when the cache is flushed, which happens on every commit.
Then, if they want more
With at-least-once the commit interval is 30 seconds, so a product getting 200 updates a minute emits about one record every 30 seconds, with the correct final value. With exactly-once it is 100 milliseconds, so you see much more.
TopologyTestDriver flushes after every input, which is why the tests showed every update, and tests asserting on intermediate values are testing something production does not do. If the downstream really needs every update, I disable caching for that store with Materialized.withCachingDisabled, or set the cache size to zero, accepting more output and changelog writes.
If they want less, a bigger cache, a longer commit interval or suppress for a fixed rate. But mostly I would explain that a table's output is latest value per key, and if they need every change event, they should consume the underlying stream instead.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A downstream team reports that updates are being lost. Explain the behaviour and how to...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/5f195fd169/