Watermarking, Event-Time vs Processing-Time & Stateful Streaming
Handle late data with watermarks and reason about event time versus processing time in stateful ops.
In plain words
Parse event instant and source watermark. Next, event-to-arrival lateness distribution. Finally, window output, late side-channel, and state cleanup.
Think of it like…
Event time is the time printed on the train ticket; processing time is when the ticket reaches the office, and the watermark is a policy for how long to keep the late-ticket box open.
Where you’ve seen it
df.withWatermark('event_ts','10 minutes').groupBy(window('event_ts','5 minutes')) closes a 5-minute window after max seen event time minus 10 minutes, not based on the wall clock alone.
Words you’ll hear
- Watermark
- A timestamp asserting when the underlying action occurred and therefore the basis for business windows.
- Event Time
- An explicit bound
max event time seen minus allowed latenessfor deciding when state may be closed. - State
- Window/aggregate/join data retained across batches by keyed event-time progress and checkpoint versions.
- Operational boundary
- A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder. Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window.
Visual diagram
Theory & deep dive
Watermark: the working mechanism
Event-time processing uses the timestamp carried by an event, processing time uses wall clock arrival, and a watermark says old events beyond a bounded delay may be ignored or handled separately.
Parse event instant and source watermark. Event-to-arrival lateness distribution, then watermark/state TTL and late policy; this exposes the state governed by State.
df.withWatermark('event_ts','10 minutes').groupBy(window('event_ts','5 minutes')) closes a 5-minute window after max seen event time minus 10 minutes, not based on the wall clock alone.
Watermarking, Event-Time vs Processing-Time & Stateful Streaming: failure mode and production response
A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window. Track Lateness p99 as "sets minimum business watermark candidate", and make State TTL visible to the dataset owner.
How it works, step by step
Step 1 of 41. Extract
Parse event instant and source watermark. Event-time processing uses the timestamp carried by an event, processing time uses wall clock arrival, and a watermark says old events beyond a bounded delay may be ignored or handled separately.
- Lateness p99
- sets minimum business watermark candidate
- Event Time
- An explicit bound `max event time seen minus allowed lateness` for deciding when state may be closed.
When to use it & trade-offs
What it is
Event-time processing uses the timestamp carried by an event, processing time uses wall clock arrival, and a watermark says old events beyond a bounded delay may be ignored or handled separately. df.withWatermark('event_ts','10 minutes').groupBy(window('event_ts','5 minutes')) closes a 5-minute window after max seen event time minus 10 minutes, not based on the wall clock alone.
Why it matters: A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder. Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window.
When to reach for it
- Handle late data with watermarks and reason about event time versus processing time in stateful ops.
- Choose Watermark because it provides this capability: A timestamp asserting when the underlying action occurred and therefore the basis for business windows.
- Keep evidence for Lateness p99 at "sets minimum business watermark candidate" so the last production stage-Close/publish - window output, late side-channel, and state cleanup-remains testable.
When to avoid or be careful
- A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
- Do not conflate Event Time with Watermark. The second concept contributes different behavior: An explicit bound
max event time seen minus allowed latenessfor deciding when state may be closed. - Release only after this guardrail is in place: Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window.
Watermark / Event Time / State - roles, limits, and operating cost
Strengths: A timestamp asserting when the underlying action occurred and therefore the basis for business windows. Event-time processing uses the timestamp carried by an event, processing time uses wall clock arrival, and a watermark says old events beyond a bounded delay may be ignored or handled separately.
Watch out: A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
max event time seen minus allowed lateness for deciding when state may be closed.Strengths: An explicit bound max event time seen minus allowed lateness for deciding when state may be closed. In this workflow it supports: Set bound - watermark/state TTL and late policy.
Watch out: The operating cost is real: cannot be shorter than required event matching or correction.
Strengths: Window/aggregate/join data retained across batches by keyed event-time progress and checkpoint versions. Its output can be checked with Watermark delay.
Watch out: Operating guardrail: Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window.
Interview signals & numbers to know
When this topic comes up
- “Where is the failure boundary for Watermark, and how would Lateness p99 reveal it?”
- “Why is Event Time distinct from this behavior: window/aggregate/join data retained across batches by keyed event-time progress and checkpoint versions?”
- Production clue: A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
- Design probe: Normalize source event time, measure lateness distribution from event-to-ingest timestamps, set watermark to a business percentile plus margin, route dropped late records, and bound state timeout with the allowed correction window.
Benchmarks & rules of thumb
- Lateness p99
- sets minimum business watermark candidate
- State TTL
- cannot be shorter than required event matching or correction
- Watermark delay
- allows lateness but delays final output
Common mistakes & follow-ups
Common interview mistakes
- A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
- Reporting success from a job exit code without checking Lateness p99 and State TTL.
- Treating this example as complete without replay, rollback, or access boundaries:
df.withWatermark('event_ts','10 minutes').groupBy(window('event_ts','5 minutes'))closes a 5-minute window after max seen event time minus 10 minutes, not based on the wall clock alone.
Likely interviewer follow-ups
- How would you prove this contract instead of only checking that the command ran: A timestamp asserting when the underlying action occurred and therefore the basis for business windows.
- What does the recovery plan do when this occurs? A timestamp parsed as local wall time shifts windows, a too-small watermark drops mobile events, and a too-large watermark retains state and delays closed-window output without reducing source disorder.
- When is Watermark insufficient for State TTL, and what does adding Event Time cost in Lateness p99?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Watermarking, Event-Time vs Processing-Time & Stateful Streaming with data engineer interview Q&A and hands-on practice.