Event TimeProcessing TimeWatermarksLate DataOut-of-OrderIdle Sources

Time & Watermarks

Time is the hardest problem in stream processing. Events arrive late, out of order, and from different time zones. Watermarks are Flink's mechanism to make sense of event time in an unbounded, disordered world.

50 min read9 sections
01

Why Time is Hard in Streaming

In batch processing, all data is available before computation starts. In streaming, data arrives continuously and you must decide when you have "enough" data to produce a result. The fundamental challenge: events don't arrive in the order they occurred.

📬

The International Mail Analogy

Imagine receiving letters from around the world. A letter mailed from Tokyo on Monday might arrive after one mailed from London on Wednesday. You can't sort your mail by 'date sent' until you're confident no more old letters are in transit. But how long do you wait? Forever means no results. Too short means missing letters. Watermarks are Flink's way of saying 'I'm reasonably confident no letters older than X are still coming.'

out-of-order.txttext
Real-world event ordering problems:

Mobile app events:
  Event generated: 10:00:01 (user taps button)
  Phone offline for 5 minutes
  Event arrives at server: 10:05:03
5 minutes late!

Multi-region events:
  US event:     generated 10:00:00, arrives 10:00:05 (5ms network)
  Asia event:   generated 09:59:58, arrives 10:00:15 (17ms network)
Asia event is EARLIER but arrives LATER

Kafka partition lag:
  Partition 0: consumer caught up, latest event time 10:05:00
  Partition 3: consumer lagging, latest event time 10:02:00
3-minute skew between partitions of the same topic

Without event-time processing:
  Window [10:00, 10:01) closes at wall-clock 10:01
  Late events silently droppedWRONG RESULTS
  Results depend on processing speedNON-DETERMINISTIC

The Core Insight

Processing time is easy but wrong — results depend on when events happen to arrive, not when they actually occurred. Event time is correct but hard — you need a mechanism (watermarks) to track progress in event time and decide when windows can close.

1 / 9