<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Watermark</id>
	<title>Watermark - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Watermark"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Watermark&amp;action=history"/>
	<updated>2026-12-06T00:08:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Watermark&amp;diff=80&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@9783fe6</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Watermark&amp;diff=80&amp;oldid=prev"/>
		<updated>2026-11-22T21:29:58Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@9783fe6&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Watermark&lt;br /&gt;
| also_known_as   = Event-time watermark, low watermark&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Event-time column, maximum observed event time, allowed delay (lateness threshold)&lt;br /&gt;
| implementations = [[Structured Streaming]] (&amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt;), [[Apache Flink]] (&amp;lt;code&amp;gt;WatermarkStrategy&amp;lt;/code&amp;gt;), Kafka Streams (grace period)&lt;br /&gt;
| related         = [[Stream processing]], [[Exactly-once semantics]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the Spark 4.3.0 Structured Streaming guides and &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt; at tag v4.3.0, the Apache Flink 2.3 documentation and the Dataflow Model paper (VLDB 2015)}}&lt;br /&gt;
&lt;br /&gt;
In [[stream processing]], a &amp;#039;&amp;#039;&amp;#039;watermark&amp;#039;&amp;#039;&amp;#039; is a moving timestamp that tells the engine how far event time has progressed in a stream, so that it can treat earlier event times as complete, emit final results for them and discard the state it kept for them. Watermarks let an engine handle data that arrives out of order while still bounding the memory and storage that stateful operators use. [[Structured Streaming]] in [[Apache Spark]] and [[Apache Flink]] both use watermarks, with different APIs and defaults.&lt;br /&gt;
&lt;br /&gt;
The word is also used for unrelated offset markers in message queues and connectors; this page covers only event-time watermarks in streaming engines.&lt;br /&gt;
&lt;br /&gt;
== Why streaming engines need watermarks ==&lt;br /&gt;
Records carry an &amp;#039;&amp;#039;&amp;#039;event time&amp;#039;&amp;#039;&amp;#039; (when the event happened) and are handled at a &amp;#039;&amp;#039;&amp;#039;processing time&amp;#039;&amp;#039;&amp;#039; (when the engine sees them). The gap between the two changes all the time, so records arrive late and out of order.&amp;lt;ref name=&amp;quot;dataflow&amp;quot;&amp;gt;{{Cite web |url=https://www.vldb.org/pvldb/vol8/p1792-Akidau.pdf |title=The Dataflow Model: A Practical Approach to Balancing Correctness, Latency, and Cost in Massive-Scale, Unbounded, Out-of-Order Data Processing |author=Tyler Akidau, Robert Bradshaw, Craig Chambers, Slava Chernyak, Rafael J. Fernández-Moctezuma, Reuven Lax, Sam McVeety, Daniel Mills, Frances Perry, Eric Schmidt, Sam Whittle |publisher=Proceedings of the VLDB Endowment, Vol. 8, No. 12 |date=2015 |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; An engine that counts events per 10-minute window cannot know when a window has received all its records.&lt;br /&gt;
&lt;br /&gt;
Without a signal, the engine has two bad choices: keep every window open forever, so that state grows without limit, or close windows by processing time, so that late records are counted in the wrong window. The Spark guide states that to run a windowed query for days, the engine must know when an old aggregate can be dropped because no more late data will arrive for it.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html |title=Structured Streaming: APIs on DataFrames and Datasets (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Dataflow paper, building on Google&amp;#039;s MillWheel, describes a watermark as a lower bound on the event times that have been processed, and notes that for most real-world data the system cannot know this bound with certainty, so watermarks are usually heuristic.&amp;lt;ref name=&amp;quot;dataflow&amp;quot; /&amp;gt; A watermark is therefore a trade-off: a longer delay accepts more late data but holds state longer and emits final results later.&lt;br /&gt;
&lt;br /&gt;
== Watermarks in Structured Streaming ==&lt;br /&gt;
Spark added watermarking in Spark 2.1. A query declares a watermark with &amp;lt;code&amp;gt;withWatermark(eventTimeColumn, delayThreshold)&amp;lt;/code&amp;gt;. At the start of every trigger, the engine sets the watermark to the maximum event time seen so far minus the delay. For a window that ends at time &amp;#039;&amp;#039;T&amp;#039;&amp;#039;, the engine keeps state and accepts late records until the watermark passes &amp;#039;&amp;#039;T&amp;#039;&amp;#039;; after that, the window&amp;#039;s state is cleared and later records for it are ignored.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The guarantee runs in one direction only. With a delay of 2 hours, the engine never drops a record that is less than 2 hours late, but a record more than 2 hours late is not guaranteed to be dropped; it may still be aggregated.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The output mode decides what the watermark does:&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In &amp;#039;&amp;#039;&amp;#039;update&amp;#039;&amp;#039;&amp;#039; mode, the engine writes changed window counts after every trigger until the window falls behind the watermark.&lt;br /&gt;
* In &amp;#039;&amp;#039;&amp;#039;append&amp;#039;&amp;#039;&amp;#039; mode, the engine writes each window once, with its final count, after the watermark passes the window&amp;#039;s end. Sinks that cannot apply fine-grained updates, such as files, use this mode.&lt;br /&gt;
* In &amp;#039;&amp;#039;&amp;#039;complete&amp;#039;&amp;#039;&amp;#039; mode, all aggregate data must be kept, so the watermark cannot drop state.&lt;br /&gt;
&lt;br /&gt;
For the watermark to clean aggregation state, the aggregation must group by the event-time column or a window on it, and &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt; must be called on that same column before the aggregation. Watermarks also bound state for stream-stream joins and for deduplication with &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt;. On a batch DataFrame, &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt; has no effect.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Multiple watermarks ===&lt;br /&gt;
When a query unions or joins several streams, each with its own watermark, Spark tracks each one and combines them into a single global watermark. By default it takes the minimum, so the query moves at the pace of the slowest stream and no stream&amp;#039;s data is dropped as too late. Since Spark 2.4, setting &amp;lt;code&amp;gt;spark.sql.streaming.multipleWatermarkPolicy&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;max&amp;lt;/code&amp;gt; makes the global watermark follow the fastest stream instead, at the cost of dropping more data from slower streams.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; The setting cannot be changed between restarts of a query from the same checkpoint location.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In Real-time Mode, records are processed as they arrive, but watermark advancement still waits for the batch boundary, which in that mode is the checkpoint interval.&amp;lt;ref name=&amp;quot;ss-rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Example ===&lt;br /&gt;
This PySpark query counts rows from the built-in &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; test source in 1-minute tumbling windows and accepts records up to 30 seconds late. In append mode, each window is printed once, after the watermark passes its end.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
from pyspark.sql.functions import window&lt;br /&gt;
&lt;br /&gt;
spark = SparkSession.builder.appName(&amp;quot;watermark-demo&amp;quot;).getOrCreate()&lt;br /&gt;
&lt;br /&gt;
events = spark.readStream.format(&amp;quot;rate&amp;quot;).option(&amp;quot;rowsPerSecond&amp;quot;, 5).load()&lt;br /&gt;
&lt;br /&gt;
counts = (&lt;br /&gt;
    events.withWatermark(&amp;quot;timestamp&amp;quot;, &amp;quot;30 seconds&amp;quot;)   # before the aggregation&lt;br /&gt;
    .groupBy(window(&amp;quot;timestamp&amp;quot;, &amp;quot;1 minute&amp;quot;))         # same column&lt;br /&gt;
    .count()&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
(counts.writeStream.outputMode(&amp;quot;append&amp;quot;)&lt;br /&gt;
    .format(&amp;quot;console&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/tmp/watermark-demo&amp;quot;)&lt;br /&gt;
    .start()&lt;br /&gt;
    .awaitTermination())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Watermarks in Apache Flink ==&lt;br /&gt;
In Flink, a watermark is an element in the stream that carries a timestamp &amp;#039;&amp;#039;t&amp;#039;&amp;#039; and declares that event time has reached &amp;#039;&amp;#039;t&amp;#039;&amp;#039;, meaning no more records with timestamps at or before &amp;#039;&amp;#039;t&amp;#039;&amp;#039; are expected.&amp;lt;ref name=&amp;quot;flink-time&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/concepts/time/ |title=Timely Stream Processing |publisher=Apache Software Foundation (Apache Flink 2.3 documentation) |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Each parallel source subtask usually generates its own watermarks, and an operator with several inputs uses the minimum of its inputs&amp;#039; event times as its current event time.&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Watermarks are defined with a &amp;lt;code&amp;gt;WatermarkStrategy&amp;lt;/code&amp;gt;, which combines a &amp;lt;code&amp;gt;TimestampAssigner&amp;lt;/code&amp;gt; (which reads the event time from each record) and a &amp;lt;code&amp;gt;WatermarkGenerator&amp;lt;/code&amp;gt;. The built-in bounded out-of-orderness strategy is the closest equivalent of Spark&amp;#039;s delay threshold:&amp;lt;ref name=&amp;quot;flink-wm&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/datastream/event-time/generating_watermarks/ |title=Generating Watermarks |publisher=Apache Software Foundation (Apache Flink 2.3 documentation) |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
WatermarkStrategy&lt;br /&gt;
        .&amp;lt;Tuple2&amp;lt;Long, String&amp;gt;&amp;gt;forBoundedOutOfOrderness(Duration.ofSeconds(20))&lt;br /&gt;
        .withTimestampAssigner((event, timestamp) -&amp;gt; event.f0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Because the combined watermark is a minimum, one idle input (for example, a Kafka partition that receives no data) holds back the watermark for the whole job. &amp;lt;code&amp;gt;withIdleness(...)&amp;lt;/code&amp;gt; lets a source mark an input as idle so that the others can advance. Watermark alignment, enabled with &amp;lt;code&amp;gt;withWatermarkAlignment(...)&amp;lt;/code&amp;gt;, stops fast sources or splits from moving too far ahead of the rest.&amp;lt;ref name=&amp;quot;flink-wm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
By default, Flink window operators drop records that arrive after the watermark has passed the end of their window; the allowed lateness is 0. &amp;lt;code&amp;gt;allowedLateness(...)&amp;lt;/code&amp;gt; keeps windows open longer and may fire them again, and &amp;lt;code&amp;gt;sideOutputLateData(...)&amp;lt;/code&amp;gt; sends dropped late records to a separate stream.&amp;lt;ref name=&amp;quot;flink-windows&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-stable/docs/dev/datastream/operators/windows/ |title=Windows |publisher=Apache Software Foundation (Apache Flink 2.3 documentation) |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Kafka Streams uses a related idea without the name: a window&amp;#039;s &amp;#039;&amp;#039;&amp;#039;grace period&amp;#039;&amp;#039;&amp;#039; controls how long the engine waits for out-of-order records, and later records are discarded for that window.&amp;lt;ref name=&amp;quot;kstreams&amp;quot;&amp;gt;{{Cite web |url=https://kafka.apache.org/44/streams/core-concepts/ |title=Kafka Streams Core Concepts |publisher=Apache Software Foundation (Apache Kafka 4.4 documentation) |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark Structured Streaming !! Apache Flink&lt;br /&gt;
|-&lt;br /&gt;
| How it is defined || &amp;lt;code&amp;gt;withWatermark(column, delay)&amp;lt;/code&amp;gt; on a DataFrame&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || &amp;lt;code&amp;gt;WatermarkStrategy&amp;lt;/code&amp;gt; on a source or stream&amp;lt;ref name=&amp;quot;flink-wm&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| What it is || A value the engine computes: max event time seen minus delay&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || An element that flows through the stream&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| When it advances || At the start of each trigger (micro-batch)&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || When the &amp;lt;code&amp;gt;WatermarkGenerator&amp;lt;/code&amp;gt; emits one; periodic generators run at an interval set with &amp;lt;code&amp;gt;ExecutionConfig.setAutoWatermarkInterval(...)&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-wm&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Several inputs || One global watermark; minimum by default, maximum with &amp;lt;code&amp;gt;spark.sql.streaming.multipleWatermarkPolicy=max&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || Each operator takes the minimum of its inputs&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Idle inputs || Under the default policy, a stalled stream holds the global watermark back&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || &amp;lt;code&amp;gt;withIdleness&amp;lt;/code&amp;gt; marks an input idle so it no longer holds the watermark back&amp;lt;ref name=&amp;quot;flink-wm&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Late records || Dropped once their window&amp;#039;s state is cleared; records within the delay are always kept&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt; || Dropped by default (allowed lateness 0); can be kept with &amp;lt;code&amp;gt;allowedLateness&amp;lt;/code&amp;gt; or captured with &amp;lt;code&amp;gt;sideOutputLateData&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-windows&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Stream processing]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Streaming lakehouse]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&lt;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>