Suppression delays intermediate updates from a windowed Kafka Streams aggregation. Instead of forwarding every revised aggregate, it buffers results per key and emits when the window closes, allowing downstream consumers to receive one final windowed result. section 9.3 section 9.7
Add suppress to the KTable produced by an aggregation, then convert it to a stream if needed for an output topic. For a page-view session aggregation, suppressing until window close prevents partial session aggregates from reaching the page-view-session-aggregates topic. section 9.3
Choose buffering behavior based on whether final-only output or continued operation under buffer pressure matters more:
- Strict buffering retains results until close and never releases an early result. An unbounded buffer guarantees final output but can consume available memory. section 9.3 section 9.3.1
- Bounded strict buffering limits records or bytes and performs a controlled shutdown when full. For example, maxRecords(10_000).shutDownWhenFull() preserves the final-only guarantee. section 9.3.1
- Eager buffering retains results only up to configured record or byte limits, then may emit before close. This avoids strict-buffer shutdowns at the cost of possible nonfinal duplicate updates. section 9.3
Suppress a session aggregate until it is final
After groupByKey, create a two-minute session window, aggregate page views, and call suppress(Suppressed.untilWindowCloses(unbounded())). The resulting stream writes only closed-session aggregates to its output topic. section 9.3
Suppression is not the only way to request final windowed results. Set emitStrategy(EmitStrategy.onWindowClose()) on a windowed aggregation when that simpler window emission policy fits; onWindowUpdate is the default. section 9.3 section 9.7
Test delayed output by advancing stream time
With TopologyTestDriver, send ten records into a one-minute suppressed window and assert that output is empty. Send a record timestamped 75 seconds later to advance stream time, then assert the prior window emits its count of 10. section 14.1.4
Figure 9.31 Eager buffering retains results up to the configured number of records or bytes and will emit results before the window closes.
Compare eager buffering's configured capacity limits with its ability to emit results before window close. section 9.3
