Inferensys

Glossary

Watermarking

Watermarking is a mechanism in stream processing that tracks event time progress, allowing the system to reason about when all data for a given time window has likely arrived and triggering windowed computations.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
STREAM PROCESSING

What is Watermarking?

Watermarking is a core mechanism in stream processing systems that tracks the progress of event time, enabling the system to reason about when all data for a given time window has likely arrived and to trigger windowed computations.

In stream processing, a watermark is a timestamp that signifies that no events with an earlier event time are expected. It is a heuristic, often based on observed processing time and event time skew, that advances monotonically through the stream. This allows stateful operations like windowed aggregation to fire and produce results for a time window once the watermark passes the window's closing boundary, providing a balance between output latency and result completeness.

Watermarks are crucial for handling out-of-order events in real-world data streams. They enable the system to manage event time processing correctly without waiting indefinitely for late data. Advanced implementations use punctuated watermarks (triggered by specific events) or periodic watermarks (generated at intervals). This mechanism is foundational for achieving correct, low-latency results in frameworks like Apache Flink and Apache Beam, forming a key part of pipeline observability for time-bound computations.

STREAM PROCESSING

Key Characteristics of Watermarking

Watermarking is a core mechanism in stream processing that tracks the progress of event time, enabling the system to reason about when all data for a given time window has likely arrived. This allows for the deterministic triggering of windowed computations and the handling of out-of-order data.

01

Event Time vs. Processing Time

Watermarking operates on event time, the timestamp when an event actually occurred, not processing time, when the system processes it. This distinction is critical for accurate analytics on real-world data where events arrive out-of-order. Watermarks track progress in event time, allowing the system to understand when it can safely assume all data for a period (e.g., 1:00 PM to 1:05 PM) has been seen, even if some late events are still trickling in during processing time.

02

Handling Out-of-Order Data

A primary function of watermarking is to manage late-arriving data. The watermark is a monotonically increasing timestamp that signifies "no events with a timestamp less than X are expected." Data arriving with a timestamp older than the current watermark is considered late. Systems can define a allowed lateness period, where late data can still be incorporated into window results, after which it is typically discarded or sent to a side output for special handling.

03

Window Triggering Mechanism

Watermarks directly control when time-based windows (e.g., tumbling, sliding, session) are evaluated and their results emitted. A window's computation is triggered only when the watermark advances past the window's end time plus any configured allowed lateness. This provides deterministic output despite the non-deterministic arrival of streaming data. For example, a 5-minute window ending at 1:05 PM will fire when the watermark passes 1:05 PM (or later, if lateness is allowed).

04

Heuristic and Perfect Watermarks

Watermarks can be generated in two primary ways:

  • Heuristic Watermarks: Estimate event time progress based on observed data patterns (e.g., using the maximum timestamp seen minus a fixed delay). This is common but can be incorrect, potentially causing late data to be missed or windows to fire prematurely.
  • Perfect Watermarks: Require knowledge of all event timestamps in advance, which is only possible with data sources that provide explicit progress guarantees (e.g., bounded logs). These guarantee no late data.
05

Source-Generated vs. Operator-Generated

Watermarks originate from data sources (e.g., Apache Kafka, Apache Pulsar) which can emit watermarks based on partition progress. Downstream operators (like window functions) receive these watermarks and propagate a combined watermark, which is the minimum of all input watermarks. This ensures a global view of progress across parallel streams. If one source partition stalls, the global watermark stalls, preventing windows from closing until all parallel inputs have advanced.

06

Impact on State Management

Watermarks enable efficient state cleanup in stateful stream processors. Once the watermark has passed the end of a window and its allowed lateness period, the system can safely garbage collect the state associated with that window. This prevents unbounded state growth. The state backend (e.g., RocksDB) relies on watermark signals to know which keyed state is no longer needed for future calculations.

STREAM PROCESSING MECHANISMS

Watermarking vs. Related Concepts

A comparison of watermarking with other core mechanisms used to manage time, state, and data flow in stream processing systems.

Feature / MechanismWatermarkingCheckpointingExactly-Once SemanticsBackpressure Handling

Primary Purpose

Tracks progress of event time to reason about completeness of time windows.

Periodically saves pipeline operator state to durable storage for failure recovery.

Guarantees each record is processed precisely once, despite failures.

Manages data flow rate to prevent fast producers from overwhelming slow consumers.

Time Domain

Event Time

Processing Time

Processing Time (for coordination)

Processing Time

Triggering Event

Ingestion of data with timestamps; heuristic or periodic generation.

Periodic timer or after processing N records.

Record acknowledgment and transaction coordination.

Downstream consumer buffer capacity or processing speed.

Data Guarantee

Completeness (all data for a time window has likely arrived).

Fault Tolerance (state can be restored).

Correctness (no duplicate or missing processing).

System Stability (prevents resource exhaustion).

State Managed

Maximum event time seen per source/partition.

Full snapshot of operator state (e.g., window buffers, counters).

Transaction logs and idempotent write markers.

Buffer queues and in-flight message counts.

Impact on Latency

Introduces intentional latency (watermark lag) for completeness.

Can increase latency during synchronous snapshot phases.

Adds coordination overhead (e.g., two-phase commit).

Reduces effective throughput to match slowest component, managing latency.

Key Implementation

Heuristic: max(event_time) - fixed_delay. Periodic: current_processing_time - allowance.

Asynchronous barrier snapshotting (Flink), Chandy-Lamport algorithm.

Idempotent sinks, transactional writes, distributed log offsets (e.g., Kafka transactions).

Credit-based flow control, blocking reads, drop-oldest/drop-newest policies.

Failure Scenario Mitigated

Late-arriving data (handled via allowed lateness or side outputs).

Worker/process failure (enables stateful recovery).

Duplicate processing after retries (ensures correct output).

Consumer crash or slowdown (prevents memory overflow and cascade failures).

WATERMARKING

Frequently Asked Questions

Watermarking is a core mechanism in stream processing for managing event time. These questions address its function, implementation, and role in ensuring data pipeline correctness.

Watermarking is a time-progress mechanism in event-time stream processing that tracks the completeness of data for a given time window, allowing the system to reason about when all events up to a certain timestamp have likely arrived and triggering computations.

In practice, a watermark is a monotonically increasing timestamp inserted into the data stream. It signifies that no events with an event time earlier than the watermark's timestamp are expected. For example, a watermark of 10:05 suggests the system believes all events timestamped before 10:05 have been ingested. This is crucial for windowed aggregations (like tumbling or sliding windows), as it tells the system when to close a window, emit its results, and discard its state. Watermarks are heuristic and handle out-of-order data by allowing a configurable allowed lateness period before finalizing a window's output.

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.