Lab · Architecture patterns

Stream windows & late events

Phones send ad clicks, each stamped with the time it happened. A counter adds them up in 10-second windows. Make phones go offline, let retries send clicks twice, and choose how long the counter waits before a window's count is final.

Try it

Lab time 3.0 s
Phones, 4 clicks a secondPhones4 clicks a second10% offlineEvent stream, clicks, any orderEvent streamclicks, any orderWindow counter, windows of 10 sWindow counterwindows of 10 swatermark 0.7 sResults, 0 windowsResults0 windows
  • Phones — 4 clicks a second — healthy — 10% offline
  • Event stream — clicks, any order — healthy
  • Window counter — windows of 10 s — healthy — watermark 0.7 s
  • Results — 0 windows — healthy
  • A click (tagged late or again when it is)
  • A window's final count
Clicks arrived
3
Dropped late
0
Counted twice
0
Windows exact
0 of 0
Result delay
—

Numbers add up:3 arrived = 3 counted + 0 dropped late + 0 late retry copies + 0 duplicates removedThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

The counter
2 s

How long past a window's end the counter waits for stragglers.

Remember click ids and ignore a second copy.

The phones
10%

They send clicks 5 to 20 s late.

0%
4

Recent windows

WindowCountedReally happenedDropped lateStatus
0–10 s3…—open

Window times are event times: when the click happened, not when it arrived. "Really happened" is shown once a window closes.

What just happened

  1. 0.0sInfo: Windows of 10 s. Late clicks are allowed for 2 s.
What this model simplifies
  • Time is slowed so you can watch each click. Windows here are 10 seconds of event time.
  • The watermark only moves when a click arrives. Real streams also move it on a timer, so a quiet stream still closes windows.
  • A late click for a closed window is dropped. Real systems can instead send a corrected result, or route late data to a separate store.
  • Windows are tumbling: back to back, with no overlap. Sliding and session windows work the same way with lateness.
  • Here "allowed lateness" is how far the watermark trails the newest click (Flink calls it bounded out-of-orderness). In Flink, allowed lateness is a second wait after the watermark, during which a late click updates a result already sent.