liveBook · Manning

KTable.suppress

As explained in Kafka Streams in Action, Second Edition

KTable.suppress is a Kafka Streams operation that buffers KTable updates and controls their downstream emission.

KTable.suppress buffers updates from a windowed aggregation so downstream consumers receive a single result when the window closes instead of intermediate results. section 9.3

Use suppression after the aggregation:

  • Call .suppress(Suppressed.untilWindowCloses(StrictBufferConfig.unbounded())). section 9.3
  • Choose strict buffering when no result should be emitted before the window closes. section 9.3
  • Apply the same pattern to session-window aggregations before converting the KTable to a stream. section 9.3

Session-window aggregation

pageViewStream.groupByKey()\n .windowedBy(SessionWindow.ofInactivityGapWithNoGrace(Duration.ofMinutes(2)))\n .aggregate(HashMap::new, sessionAggregator, sessionMerger)\n .suppress(Suppressed.untilWindowCloses(unbounded()))\n .toStream() section 9.3

Figure 9.30 Strict buffering retains all results and never emits one before a window closes.
figure

Shows how strict buffering retains all results and prevents emission before a window closes. section 9.3

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Demonstrates the one-line API and session-window placement, while deferring several suppression details.
Examples
Uses tumbling-window and pageview session-window aggregations with strict buffering.
What it assumes
Assumes familiarity with KStream grouping, windowing, aggregation, and converting a KTable to a stream.
What you can do after
Apply it via Kafka Streams to emit one final result when a window closes.
How it connects
Connects KTable.suppress to windowed aggregation, session windows, KStream, and EmitStrategy.

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.