Event time and processing time
| Also known as | Event-time and processing-time semantics |
|---|---|
| Field | Stream processing |
| Key parts | Event timestamp carried in the record, clock of the processing machine, skew between them, watermark |
| Open source implementations | Structured Streaming in Apache Spark, Apache Flink, Kafka Streams |
| Related | Watermark, Windowing (stream processing), Stream processing |
python/pyspark/sql/functions/builtin.py at tag v4.3.0 of apache/spark, the Apache Flink 2.3 "Timely Stream Processing" page, the Kafka Streams 4.4 core concepts page and the Dataflow Model paper (VLDB 2015).In stream processing, event time is the time at which an event actually happened, recorded in the event itself, and processing time 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, watermarks and stateful operators use it to produce results that do not depend on arrival order.[1]
What is event time?
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.[1]
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.[2]
What is processing time?
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.[2] 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.[2]
Some sources add a third notion, ingestion time, 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 timestamp column, together with a timestampType column, next to key, value, topic, partition and offset.[3]
Why do event-time and processing-time results differ?
The Dataflow paper from Google describes the gap between the two clocks as skew: 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.[4]
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.[5]
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'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.[2]
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.[2] A watermark expresses that waiting time.
How does Structured Streaming use event time?
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.[1] The window, session_window and window_time functions take this column as input, and withWatermark declares how late it may be.[5]
Spark has no separate processing-time API for windows. The session_window documentation notes that a streaming query can use the current_timestamp function to generate windows on processing time.[6] Processing time also governs when micro-batches run, through the trigger, and the processing-time timers and TTL of transformWithState.
Example
This PySpark query counts clicks per 10-minute window by event time. The event_time column comes from the JSON payload; the Kafka timestamp column is kept only to show the difference. A click with an event_time 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.
from pyspark.sql import functions as F
raw = (spark.readStream.format("kafka")
.option("kafka.bootstrap.servers", "broker:9092")
.option("subscribe", "clicks")
.load())
clicks = raw.select(
F.from_json(F.col("value").cast("string"),
"user STRING, page STRING, event_time TIMESTAMP").alias("c"),
F.col("timestamp").alias("kafka_time"), # set by Kafka
).select("c.*", "kafka_time")
per_window = (clicks
.withWatermark("event_time", "15 minutes")
.groupBy(F.window("event_time", "10 minutes"), "page")
.count())
Grouping by kafka_time instead would count the same click in the window that starts at 12:10.
Event time and processing time in other engines
| Spark Structured Streaming | Apache Flink | Kafka Streams | |
|---|---|---|---|
| How event time is set | A timestamp column in the DataFrame, named in window and withWatermark[5]
|
A TimestampAssigner in a WatermarkStrategy[2]
|
A TimestampExtractor that reads a timestamp from each record[7]
|
| How event-time progress is tracked | Watermark: maximum event time seen minus the delay[5] | Watermarks that flow through the stream[2] | Stream time, which advances only when new records arrive[7] |
| Processing-time windows | By windowing on current_timestamp[6]
|
Built-in processing-time window assigners[2] | A TimestampExtractor that returns the current wall-clock time[7]
|
See also
- Watermark
- Windowing (stream processing)
- Stream processing
- Structured Streaming
- Exactly-once semantics
References
- ↑ 1.0 1.1 1.2 Structured Streaming Programming Guide: Handling Event-time and Late Data (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 Timely Stream Processing (Apache Flink 2.3). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ Structured Streaming + Kafka Integration Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 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.The Dataflow Model: A Practical Approach to Balancing Correctness, Latency, and Cost in Massive-Scale, Unbounded, Out-of-Order Data Processing. Proceedings of the VLDB Endowment, Vol. 8, No. 12, 2015.Retrieved 2026-11-23.
- ↑ 5.0 5.1 5.2 5.3 Structured Streaming: Handling Late Data and Watermarking (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 6.0 6.1 python/pyspark/sql/functions/builtin.py (Apache Spark v4.3.0). Apache Software Foundation.Retrieved 2026-11-23.
- ↑ 7.0 7.1 7.2 Kafka Streams Core Concepts (Apache Kafka 4.4). Apache Software Foundation.Retrieved 2026-11-23.