Highlights

Contents

Part IV
04

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.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1OLTP vs OLAP2Batch processing3Stream processing4Event time, windows,watermarks5ETL, ELT, warehouses, andlakes6CDC and materializedviews7Checkpoints andexactly-once8Spark and Flink9Case study: score toreport

#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.

ARRIVAL ORDER a, b, c, d; EVENT TIMES 1, 3, 2, 7. c IS LATE RELATIVE TO bARRIVAL ORDER a, b, c, d; EVENT TIMES 1, 3, 2, 7. c IS LATE RELATIVE TO barrivalabcd012345678event timeabcdevent time answers "when did it happen"; processing time "when did we see it"
Figure 17.13Computed illustrative event-time sequence. The third arrival is out of timestamp order.

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.

TUMBLING 5 S WINDOWS: [0,5) HOLDS a, b, c (RED 6, BLUE 3); [5,10) HOLDS d (RED 1)TUMBLING 5 S WINDOWS: [0,5) HOLDS a, b, c (RED 6, BLUE 3); [5,10) HOLDS d (RED 1)[0, 5)[5, 10)abcdred 2 + 4 = 6 · blue 3red 1 · blue 0012345678910include the left edge, exclude the right, so time 5 lands in exactly one window
Figure 17.14Computed illustrative event-time tumbling windows. Interval width is a teaching assumption.

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 7−2=57-2=5. 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.

A WATERMARK MARKS EVENT-TIME PROGRESS UNDER A DISORDER POLICYA WATERMARK MARKS EVENT-TIME PROGRESS UNDER A DISORDER POLICY01234567watermark 5max observed 72 s allowed disorder7 − 2 = 5; interval [0,5) eligible by this rule
Figure 17.15Computed illustrative bounded-disorder watermark. Late-data handling remains necessary after the signal advances.

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.

AN EVENT AT TIME 2 ARRIVES AFTER [0,5) WAS EMITTED: UPDATE, REPAIR, OR COUNT AS DROPPEDAN EVENT AT TIME 2 ARRIVES AFTER [0,5) WAS EMITTED: UPDATE, REPAIR, OR COUNT AS DROPPEDtime = 2window statestill retained?yes: emit a new versionno: repair jobbeyond policy: count itfinality is a declared policy, never silent
Figure 17.16Illustrative late-record branches. The policy determines whether the previously emitted result can change.

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.