100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Big Data & Distributed Computing
30 minintermediate

Watermarks and Late-Arriving Data

Late-arriving data is a fundamental challenge of stream processing: events may arrive minutes or hours after generation, due to network delays, device reconnection, or intermediate system buffering. A streaming pipeline ignoring late data produces incorrect aggregations — a bowler's economy computed from only the deliveries that arrived on time, silently missing late ones. Watermarks are the mechanism Spark Structured Streaming uses to handle this: a bounded delay tolerance that allows late events to update previously computed results while discarding events that arrive too late.

The watermark is a threshold defined relative to event time: `withWatermark('event_ts', '10 minutes')` tells Spark that events may arrive up to 10 minutes late, and any event with a timestamp more than 10 minutes behind the current maximum observed timestamp should be considered too late and dropped. Spark computes the current watermark as `max(observed_event_time) - delay_threshold` and advances it monotonically. Windows whose end time is earlier than the current watermark are finalised, emitted in `append` mode, and their state memory released.

Analogy🏏Cricket
🏏 Think of it like cricket: Imagine the DRS review system deployed across three independent video-review centres in Mumbai, Chennai, and London, each holding a copy of the ball-tracking data. A CAP partition is a network outage that cuts communication between them. A CP system says: if the centres cannot synchronise, no review decision is issued — no player walks until the system is restored. Consistency is guaranteed; availability is sacrificed. An AP system says: each centre issues its own decision based on its local data, even if that means Mumbai says out and London says not out — reviews continue but different centres may give different verdicts. Partition tolerance is non-negotiable because the network always has the possibility of failing; the choice is whether umpires wait for consensus or proceed with local data.
Lesson 26 of 35
0% complete