Event time, windows, watermarks
We ask when the event happened rather than only when the worker saw it. Network delay can put the same history into a different arrival order. We will trace windows, watermarks, late events, and bounded state without claiming that a clock makes data complete.
#Section 13Arrival time is not occurrence time
The four illustrative records have event times 1, 3, 2, and 7. The third record arrives after the second even though it happened earlier. Event time is a timestamp describing when the business event occurred. Processing time is when a particular operator handles it. They can differ because of network delay, batching, offline clients, and retries.
An event-time aggregate assigns a record using its declared occurrence time. A processing-time aggregate assigns it using the worker’s observation clock. Both are valid when they answer the intended question. A report about plays within a match interval generally wants event time; a dashboard about current ingestion load wants processing observations.
Validate timestamps and their trust source. A client can submit an implausible future time that pushes a naive progress rule forward. Clock skew and corrections require a declared policy. Event time is data, not guaranteed truth; processing time is an observation, not the same business moment.
#Section 14Windows bound an otherwise open aggregate
A season-to-date sum can remain open, but a report may need totals for fixed intervals. A window groups records according to a time or count boundary. An illustrative five-second tumbling window uses non-overlapping intervals [0,5) and [5,10). The left boundary is included and the right excluded, so every timestamp belongs to one interval.
Events at times 1, 3, and 2 belong to the first window. Red contributes 2 and 4, giving 6; blue contributes 3. Event time 7 belongs to the second window, where red contributes 1. A tumbling window has consecutive non-overlapping boundaries, while a sliding window can include a record in several overlapping intervals.
A record exactly at time five belongs to the second interval under the stated half-open rule, not both. Window assignment happens before aggregation, so the rule must remain consistent during replay and backfill. A timezone or timestamp-unit conversion applied differently in another run can change membership even when the raw event is identical.
A session window groups activity separated by sufficiently short inactivity gaps. It can require merging previously separate groups when a late event connects them. State retention and output updates therefore depend on window type. Do not assume every window can close simply because a worker’s clock reaches the interval end.
#Section 15A watermark states a progress assumption
The processor has observed a maximum event time of 7 and allows an illustrative two-second out-of-order margin. A simple watermark rule produces . A watermark is a progress signal expressing that the system believes ordinary relevant events before a point have arrived under its chosen assumptions.
The five-second window can become eligible for output or cleanup according to the engine’s watermark and boundary rules. This is not proof that no older event can ever arrive. The system still needs a late-data policy for events violating the assumption. The rule is a controlled trade between latency, completeness, and retained state.
Multiple input partitions may advance at different rates. Combining them conservatively often requires the minimum relevant input watermark; otherwise a fast partition can cause the job to finalize before a slow one delivers its records. An idle partition needs an explicit idleness policy or it can hold progress forever. Flink’s time documentation describes event time and watermarks in its execution model.
#Section 16Late events need an output policy
After a window is emitted, a record with time 2 arrives. Options include updating the window, routing the record to a late-data repair path, or dropping it under an explicitly lossy contract. Allowed lateness defines how long or under what progress boundary the job keeps a window able to accept such corrections.
An updatable result should carry a key and version so the sink can replace the earlier value. An append-only sink can instead publish correction events whose semantics readers understand. If late records are discarded, count them and make the resulting completeness limit visible. A hidden drop can bias totals while normal throughput looks healthy.
Window state costs grow with keys, active windows, lateness horizon, and operator data per key. A larger delay budget retains more state and can increase checkpoint and recovery cost. The useful question is which lateness the product must accommodate and how exceptional older data is repaired. Infinite retention is not a recovery design.