Skip to the page

Streaming and CDC · mid

Event time, watermarks and windows

Event time is when something happened, processing time is when the job sees it. A watermark says how late data may be, closes windows and bounds state. Late events beyond it are dropped.

The notes

What you must know

  • Event time is when the order happened on the phone. Processing time is when the job sees it. They differ because of networks, offline phones, retries and backlogs. Business numbers use event time.
  • Watermark = the latest event time seen minus an allowed delay. Windows that end before the watermark are final: in append mode they are emitted once and their state is dropped. Events older than the watermark are dropped.
  • Trade-off: a longer delay is more complete but keeps more state and emits later.
  • Example: latest event time 10:20 and delay 10 minutes gives watermark 10:10. The 10:00 to 10:05 window is final and written. A 10:03 order arriving now is dropped silently. Spark reports it as numRowsDroppedByWatermark.
  • The watermark moves with data, not with the clock. If no events arrive, the last windows are not closed until new events come.
  • Windows: tumbling (00:00-00:05, 00:05-00:10), sliding (10 minutes long every 5) and session (activity until a gap).
  • Output modes: append emits each window once when final; update emits changed rows each batch; complete re-emits everything and never cleans state. Without a watermark, stateful aggregation keeps state for ever.
  • Spark uses one global watermark per query. If some Kafka partitions fall far behind, their events can be dropped as late even though nothing was late on the phones. Flink tracks watermarks per source partition and an idle partition can hold it back (withIdleness).
  • A live dashboard lower than the next-day report: compare definitions, the day boundary and sources first. The batch report from the database is the number of record; label the live number as an estimate. Fix lag with capacity and maxOffsetsPerTrigger, a longer watermark or corrections, CDC from the orders database, and an alert on dropped rows.

The red pen

Common traps: mistake → fix

  • Mistake: The watermark is a timeout

    Fix: it is a promise about how late data can be.

  • Mistake: Windows are written at 10:05 by the clock

    Fix: they close when the watermark passes the end.

  • Mistake: Late events cause errors

    Fix: they are dropped silently unless you track the metric.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is the difference between event time and processing time?
  2. What does a watermark do?
  3. The latest event time is 10:20 and the watermark delay is 10 minutes. Is the 10:00 to 10:05 window written?
  4. The live dashboard shows 212 crore and the next day report 219 crore. Why?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview