Group a KStream by key using groupByKey or groupBy with appropriate serdes.
Define a window using TimeWindows.ofSizeWithNoGrace(Duration) or, for late-arrival tolerance, TimeWindows.ofSizeAndGrace(windowSize, gracePeriod).
Apply an aggregate using windowedBy(windows).aggregate(initializer, aggregator, Materialized.as(...)).
The grace period controls how long Kafka Streams accepts late records into already-emitted windows; records arriving after the grace period are dropped.
Configure suppress(Suppressed.untilWindowCloses(unbounded())) if you want to emit only the final result after the window and grace period both close.
Verify late record handling by producing out-of-order records to the input topic and inspecting whether they are included in the window aggregate.
Known gotchas
Without suppress, Kafka Streams emits intermediate results for every record that updates a window; downstream consumers must handle multiple updates for the same window key.
Grace period is measured in stream time, not wall-clock time; if the input stream is idle, stream time does not advance and windows do not close.
Very large grace periods combined with suppress can cause unbounded state store growth; always estimate worst-case state size before setting grace periods.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp