Notesstream🌱 seedling

Windowing

Also: Window · Tumbling Window · Hopping Window · Sliding Window · Session Window · Cumulating Window · Global Window

Windows slice an unbounded stream into finite, per-key groups by event time, so aggregates and joins can finish. The window shape (tumbling, hopping, session) decides how many results you get, how much state you hold, and when a result can be emitted.

Why it exists

An aggregate over an infinite stream never completes. Windows bound both the computation and the state, and give each result a time it belongs to.

How it works

  • Tumbling: fixed size, no overlap. Each event is in exactly one window (per-minute metrics, billing).
  • Hopping (sliding): fixed size, advancing by a smaller slide. Each event is in size/slide windows (moving averages).
  • Session: per key, closed after an inactivity gap. A late event can bridge two sessions and merge them.
  • Cumulating: grows within a period ("so far today, every minute"). Global: one window per key, which needs a custom trigger.
  • A window's state lives until the Watermark passes its end, plus any allowed lateness.

Trade-offs

Window Gains Costs
tumbling simple, one result per period bursts split across boundaries
hopping smooth trends size/slide × state and output
session matches user behaviour data-dependent boundaries, merges, unbounded if keys never go quiet

In practice

  • Flink: DataStream window assigners, plus the SQL window TVFs TUMBLE, HOP, CUMULATE and SESSION (SESSION since 1.19).
  • Kafka Streams: tumbling, hopping, sliding and session windows. Since 3.0 you choose the grace period explicitly.

Pitfalls

  • Tiny slides on hopping windows multiply state and output.
  • Session windows on keys that never go quiet (bots, health checks) never close.
  • Windowing in processing time by accident.

Recall

These cards are also in your review deck, scheduled with spaced repetition.