<?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=Event_time_and_processing_time</id>
	<title>Event time and processing time - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Event_time_and_processing_time"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Event_time_and_processing_time&amp;action=history"/>
	<updated>2026-12-06T00:07:31Z</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=Event_time_and_processing_time&amp;diff=145&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Event_time_and_processing_time&amp;diff=145&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:40Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&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            = Event time and processing time&lt;br /&gt;
| also_known_as   = Event-time and processing-time semantics&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Event timestamp carried in the record, clock of the processing machine, skew between them, [[watermark]]&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]], [[Apache Flink]], Kafka Streams&lt;br /&gt;
| related         = [[Watermark]], [[Windowing (stream processing)]], [[Stream processing]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide and Kafka integration guide, &amp;lt;code&amp;gt;python/pyspark/sql/functions/builtin.py&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the Apache Flink 2.3 &amp;quot;Timely Stream Processing&amp;quot; page, the Kafka Streams 4.4 core concepts page and the Dataflow Model paper (VLDB 2015)}}&lt;br /&gt;
&lt;br /&gt;
In [[stream processing]], &amp;#039;&amp;#039;&amp;#039;event time&amp;#039;&amp;#039;&amp;#039; is the time at which an event actually happened, recorded in the event itself, and &amp;#039;&amp;#039;&amp;#039;processing time&amp;#039;&amp;#039;&amp;#039; is the time on the clock of the machine that handles the event. The two differ because events are delayed by networks, queues, retries and outages, so a stream processor that groups by event time and one that groups by processing time can give different answers for the same data. In [[Apache Spark]] [[Structured Streaming]], event time is an ordinary timestamp column of a DataFrame, and windows, [[watermark]]s and stateful operators use it to produce results that do not depend on arrival order.&amp;lt;ref name=&amp;quot;ss-start&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/getting-started.html#handling-event-time-and-late-data |title=Structured Streaming Programming Guide: Handling Event-time and Late Data (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is event time? ==&lt;br /&gt;
Event time is the timestamp that describes when something happened: when a sensor took a reading, when a user clicked, when a payment was authorized. The Spark programming guide defines event time as the time embedded in the data itself, and uses the example of counting events generated by IoT devices per minute by the time the device produced them rather than the time Spark received them.&amp;lt;ref name=&amp;quot;ss-start&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the Flink documentation, event time is the time each event occurred on its producing device; it is usually embedded in the record before it reaches the engine, and the progress of event time depends on the data, not on any wall clock.&amp;lt;ref name=&amp;quot;flink-time&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/concepts/time/ |title=Timely Stream Processing (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is processing time? ==&lt;br /&gt;
Processing time is the system time of the machine that runs an operator at the moment it handles a record. An hourly processing-time window contains whatever records reached the operator while its clock showed that hour.&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt; Processing time needs no coordination between machines and gives the lowest latency, but its results depend on how fast records arrive and move through the system, and on outages, so they are not deterministic.&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Some sources add a third notion, &amp;#039;&amp;#039;&amp;#039;ingestion time&amp;#039;&amp;#039;&amp;#039;, the time at which a record entered the pipeline, for example when a Kafka broker appended it to a partition. The [[Apache Kafka]] source in Spark exposes this kind of timestamp as the &amp;lt;code&amp;gt;timestamp&amp;lt;/code&amp;gt; column, together with a &amp;lt;code&amp;gt;timestampType&amp;lt;/code&amp;gt; column, next to &amp;lt;code&amp;gt;key&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;value&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;topic&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;partition&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;offset&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;ss-kafka&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-kafka-integration.html |title=Structured Streaming + Kafka Integration Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Why do event-time and processing-time results differ? ==&lt;br /&gt;
The Dataflow paper from Google describes the gap between the two clocks as &amp;#039;&amp;#039;&amp;#039;skew&amp;#039;&amp;#039;&amp;#039;: the event time of an event never changes, but the skew between event time and processing time changes constantly, 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-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Spark guide gives a concrete case. A word generated at 12:04 (event time) reaches the application at 12:11 (processing time). A count by event time adds the word to the window 12:00 to 12:10; a count by arrival time would put it in a later window. Structured Streaming keeps the partial aggregate for the older window so that the late record still updates 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#handling-late-data-and-watermarking |title=Structured Streaming: Handling Late Data and Watermarking (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Reprocessing shows the same effect. Event-time results are the same whether a day of data is processed live or replayed a week later, because the timestamps come from the data. Processing-time results of a replay depend on when the replay ran. Flink&amp;#039;s documentation states that event-time operations give consistent results for out-of-order or late events and when reprocessing historic data, provided all the data has arrived.&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Event time has a cost: the engine must wait for late records before it can call a result final. Because it can only wait for a finite time, event-time processing has a limit on how deterministic it can be.&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt; A [[watermark]] expresses that waiting time.&lt;br /&gt;
&lt;br /&gt;
== How does Structured Streaming use event time? ==&lt;br /&gt;
Structured Streaming treats each event as a row and event time as a column of that row, so a window over event time is a grouping key like any other. The same event-time window query can therefore run on a static DataFrame of historical logs and on a stream.&amp;lt;ref name=&amp;quot;ss-start&amp;quot; /&amp;gt; The &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;window_time&amp;lt;/code&amp;gt; functions take this column as input, and &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt; declares how late it may be.&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark has no separate processing-time API for windows. The &amp;lt;code&amp;gt;session_window&amp;lt;/code&amp;gt; documentation notes that a streaming query can use the &amp;lt;code&amp;gt;current_timestamp&amp;lt;/code&amp;gt; function to generate windows on processing time.&amp;lt;ref name=&amp;quot;builtin&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/functions/builtin.py |title=python/pyspark/sql/functions/builtin.py (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Processing time also governs when micro-batches run, through the [[Trigger (Structured Streaming)|trigger]], and the processing-time timers and TTL of [[transformWithState]].&lt;br /&gt;
&lt;br /&gt;
== Example ==&lt;br /&gt;
This PySpark query counts clicks per 10-minute window by event time. The &amp;lt;code&amp;gt;event_time&amp;lt;/code&amp;gt; column comes from the JSON payload; the Kafka &amp;lt;code&amp;gt;timestamp&amp;lt;/code&amp;gt; column is kept only to show the difference. A click with an &amp;lt;code&amp;gt;event_time&amp;lt;/code&amp;gt; of 12:04 that arrives at 12:11 is still counted in the window that starts at 12:00, as long as it is within the 15-minute watermark delay.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import functions as F&lt;br /&gt;
&lt;br /&gt;
raw = (spark.readStream.format(&amp;quot;kafka&amp;quot;)&lt;br /&gt;
       .option(&amp;quot;kafka.bootstrap.servers&amp;quot;, &amp;quot;broker:9092&amp;quot;)&lt;br /&gt;
       .option(&amp;quot;subscribe&amp;quot;, &amp;quot;clicks&amp;quot;)&lt;br /&gt;
       .load())&lt;br /&gt;
&lt;br /&gt;
clicks = raw.select(&lt;br /&gt;
    F.from_json(F.col(&amp;quot;value&amp;quot;).cast(&amp;quot;string&amp;quot;),&lt;br /&gt;
                &amp;quot;user STRING, page STRING, event_time TIMESTAMP&amp;quot;).alias(&amp;quot;c&amp;quot;),&lt;br /&gt;
    F.col(&amp;quot;timestamp&amp;quot;).alias(&amp;quot;kafka_time&amp;quot;),      # set by Kafka&lt;br /&gt;
).select(&amp;quot;c.*&amp;quot;, &amp;quot;kafka_time&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
per_window = (clicks&lt;br /&gt;
    .withWatermark(&amp;quot;event_time&amp;quot;, &amp;quot;15 minutes&amp;quot;)&lt;br /&gt;
    .groupBy(F.window(&amp;quot;event_time&amp;quot;, &amp;quot;10 minutes&amp;quot;), &amp;quot;page&amp;quot;)&lt;br /&gt;
    .count())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Grouping by &amp;lt;code&amp;gt;kafka_time&amp;lt;/code&amp;gt; instead would count the same click in the window that starts at 12:10.&lt;br /&gt;
&lt;br /&gt;
== Event time and processing time in other engines ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! Spark Structured Streaming !! Apache Flink !! Kafka Streams&lt;br /&gt;
|-&lt;br /&gt;
! How event time is set&lt;br /&gt;
| A timestamp column in the DataFrame, named in &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;TimestampAssigner&amp;lt;/code&amp;gt; in a &amp;lt;code&amp;gt;WatermarkStrategy&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;TimestampExtractor&amp;lt;/code&amp;gt; that reads a timestamp from each record&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 (Apache Kafka 4.4) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! How event-time progress is tracked&lt;br /&gt;
| Watermark: maximum event time seen minus the delay&amp;lt;ref name=&amp;quot;ss-apis&amp;quot; /&amp;gt;&lt;br /&gt;
| Watermarks that flow through the stream&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Stream time&amp;#039;&amp;#039;&amp;#039;, which advances only when new records arrive&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Processing-time windows&lt;br /&gt;
| By windowing on &amp;lt;code&amp;gt;current_timestamp&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;builtin&amp;quot; /&amp;gt;&lt;br /&gt;
| Built-in processing-time window assigners&amp;lt;ref name=&amp;quot;flink-time&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;TimestampExtractor&amp;lt;/code&amp;gt; that returns the current wall-clock time&amp;lt;ref name=&amp;quot;kstreams&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Windowing (stream processing)]]&lt;br /&gt;
* [[Stream processing]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Exactly-once semantics]]&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>