liveBook · Manning

Suppression

As explained in Kafka Streams in Action, Second Edition

Suppression is a Kafka Streams technique that delays intermediate results and emits a result only when its configured conditions are met.

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.
figure

Compare eager buffering's configured capacity limits with its ability to emit results before window close. section 9.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains per-key buffering, strict and eager tradeoffs, bounded shutdown behavior, and stream-time testing.
Examples
Uses page-view session aggregation and a one-minute tumbling-count test that advances timestamps to release output.
What it assumes
Assumes Kafka Streams windowed aggregations and introduces suppression configuration from a minimal operator call.
What you can do after
Apply it via Kafka Streams APIs to emit final windowed aggregates and test their delayed output.
How it connects
Connects windowed aggregation with KTable, session windows, EmitStrategy, stream time, and TopologyTestDriver.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.