A sliding window continuously analyzes a fixed-duration portion of an event stream. Record timestamps determine each window’s start and end, while the configured maximum time difference fixes its size. section 9.1.4
Use these rules to distinguish sliding windows from other Kafka Streams windows:
- Each incoming record creates a new window and looks back for records whose timestamps fall within the configured time difference. section 9.1.4
- Window start and end times are inclusive, unlike the end boundary of hopping and tumbling windows. section 9.1.4
- Windows evaluate when records enter or leave their contents, rather than on a fixed recurring schedule. section 9.1.4
- Unlike epoch-aligned time windows, sliding-window boundaries follow event timestamps. section 9.1.5
Page-view aggregation
A Kafka Streams application can aggregate page views in 30-second sliding windows: KStream pageViewStream = builder.stream("page-view", Consumed.with(serdeString, pageViewSerde)); pageViewStream.groupByKey() .windowedBy(SlidingWindows.ofTimeDifferenceWithNoGrace(Duration.ofSeconds(30))) .aggregate(HashMap::new, pageViewAggregator) .toStream() .to("page-view-sliding-aggregates", Produced.with(windowedSerdes, pageViewAggregationSerde)); The application emits an updated aggregate as records change the window contents. section 9.1.4 section 9.7
Figure 9.16 Sliding windows starting and ending times are inclusive and look back for events occurring within the defined time difference.
Trace how each incoming record establishes an inclusive window and looks back for nearby timestamped events. section 9.1.4




