Inferensys

Glossary

Watermark

A mechanism in stream processing that tracks the progress of event time, providing a threshold to indicate that all data up to a certain timestamp has been received, thus handling out-of-order data.
Data scientist building training data pipeline on laptop, data preprocessing visible, technical workspace.
STREAM PROCESSING FUNDAMENTALS

What is a Watermark?

A watermark is a mechanism in stream processing that tracks the progress of event time, providing a threshold to indicate that all data up to a certain timestamp has been received, thus handling out-of-order data.

A watermark is a monotonically increasing timestamp injected into a data stream to declare that no events with a timestamp earlier than the watermark will be observed. It serves as a heuristic assertion of completeness, allowing a stream processor to close windowing operations and emit results without waiting indefinitely for late-arriving data. The watermark advances based on observed event timestamps minus a configured allowed lateness bound.

Watermarks are essential for handling the inherent skew between event time and processing time in distributed systems. When a stream processor receives a watermark T, it triggers computations for all windows with an end time less than or equal to T. This mechanism enables correct, deterministic results over unbounded, out-of-order data, balancing result latency against completeness in architectures like Apache Flink and Google Dataflow.

TEMPORAL PROGRESS TRACKING

Key Characteristics of Watermarks

Watermarks are the fundamental mechanism that allows stream processors to reason about event time completeness in the face of out-of-order data. They provide a declarative threshold that tells the system, 'all events with a timestamp earlier than T have likely arrived,' enabling correct windowing and state management.

01

Event Time vs. Processing Time

Watermarks bridge the critical gap between event time (when something happened) and processing time (when the system observed it). In distributed systems, these timelines diverge due to network latency, clock skew, and backpressure. A watermark is a monotonically increasing timestamp that declares the system's best estimate of event time progress. It allows operators to say, 'I have observed all data up to 12:01:00,' even if the processing clock reads 12:05:00. This decoupling is essential for deterministic, reproducible results regardless of when computation executes.

02

Handling Out-of-Order Data

The primary purpose of a watermark is to define a grace period for late-arriving data. Without watermarks, a window operator would never know when to materialize results. Key behaviors include:

  • Heuristic Generation: Watermarks are typically derived by observing the maximum event timestamp seen so far, minus a configurable allowed lateness bound.
  • Idleness Handling: If a source partition goes silent, the watermark must not stall. Systems like Apache Flink use idle timeout mechanisms to mark partitions as idle and advance the watermark based on other active partitions.
  • Late Data Routing: Events arriving after the watermark has passed their window are considered late. They can be discarded, logged to a side output, or used to issue corrective updates depending on the processing mode.
03

Watermark Propagation in DAGs

In a directed acyclic graph (DAG) of stream operators, watermarks flow downstream alongside data. When an operator consumes multiple input streams, it must compute an input watermark by taking the minimum of all upstream watermarks. This conservative approach ensures correctness: a multi-input join or union cannot safely process up to time T until all its inputs have reached T. This propagation logic is critical for maintaining exactly-once semantics in stateful operations and prevents premature window firings that would produce incomplete results.

04

Periodic vs. Punctuated Watermarks

Stream processors support two generation strategies:

  • Periodic Watermarks: Generated at a fixed interval (e.g., every 200ms). The generator inspects the current maximum event time and emits a watermark. This is efficient for high-throughput streams where per-event overhead is prohibitive.
  • Punctuated Watermarks: Generated in response to specific events in the stream. A sensor might emit a 'batch complete' marker, or a data file might contain an end-of-file record. This provides precise, data-driven progress tracking but requires the source to embed such signals. The choice involves a trade-off between latency (how quickly a window fires) and computational overhead.
05

Allowed Lateness and Side Outputs

The watermark defines the point of no return for a window, but systems often allow a configurable allowed lateness period beyond the watermark. During this grace period, a window remains in memory, and late events update the result. Once allowed lateness expires, the window state is cleaned up. Events arriving after this final deadline are routed to a side output—a separate stream that acts as a dead letter queue for late data. This pattern enables:

  • Corrective updates to downstream sinks.
  • Auditability of data quality issues.
  • Separate business logic for processing stragglers without blocking the main pipeline.
06

Watermark Skew and Skew Mitigation

In a distributed system, different source partitions progress at different rates. A single slow partition can hold back the entire watermark, causing watermark skew and delaying all window outputs. Mitigation strategies include:

  • Idle source detection: Automatically marking stalled partitions as idle after a timeout.
  • Watermark alignment: In structured streaming, applying a maximum acceptable skew between partitions.
  • Speculative execution: Proactively processing data assuming a partition is complete, with rollback mechanisms if late data later arrives. Without these techniques, a single straggling Kafka partition can stall a global aggregation indefinitely.
STREAM PROCESSING FUNDAMENTALS

Frequently Asked Questions

Clear, technical answers to the most common questions about watermarks in stream processing, covering their role in handling out-of-order data and triggering computations.

A watermark is a mechanism in stream processing that tracks the progress of event time, providing a threshold to indicate that all data up to a certain timestamp has been received. It is a monotonically increasing timestamp injected into the data stream by the system or the application. When a watermark with timestamp T passes through a streaming operator, it signals that no more events with an event time earlier than T are expected to arrive, allowing the operator to finalize and emit results for time windows ending at or before T. This is critical for handling out-of-order data and ensuring correct, deterministic results in the face of network delays and distributed system imperfections.

TEMPORAL PROGRESS TRACKING

Watermark vs. Related Concepts

How watermarks differ from other stream processing mechanisms for managing time and data completeness

FeatureWatermarkCheckpointingWindowingEvent Time

Primary purpose

Track event-time progress and handle lateness

Save operator state for fault recovery

Divide unbounded streams into finite chunks

Timestamp when event actually occurred

Handles out-of-order data

Triggers computation

Persists state to durable storage

Defines temporal boundaries

Recovers from failures

Typical granularity

Millisecond-level threshold

Application-defined interval

Fixed, sliding, or session windows

Per-event timestamp

Late data handling

Discards or routes to side output

Not applicable

Updates window results if allowed

Not applicable

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.