Event-time feature aggregation
Define window membership independently of processing order, then specify watermark, trigger, lateness, and correction behavior.
On this page
The question for today
What you’ll understand
- Compute a half-open event-time aggregate at a decision boundary.
- Explain watermarks as a progress contract with late-data policy.
- Distinguish cumulative revisions from additive output deltas.
A rolling feature is defined over events, but the system receives those events through delayed and reordered messages. Processing whatever arrived in the last ten minutes is not necessarily the same feature as counting events whose event timestamps belong to the last ten minutes. Window membership, publication timing, and the treatment of later corrections must be designed separately.
Define membership before discussing when to emit
Specify the entity key, event identifier, qualifying predicate, event timestamp, and precise interval. A ten-minute window ending at a prediction might include its lower boundary and exclude its upper boundary. An event exactly at prediction time then belongs to the next interval under that convention. Distinguish tumbling windows from overlapping sliding windows and continuously rolling features; a stored completed bucket is not automatically the exact rolling value at every request time. Document any approximation introduced by bucket resolution.
Out-of-order processing should not change membership in a deterministic event-time definition, although it can change which provisional result was available to a historic prediction. A late-known event can legitimately revise corrected history without having been visible at that original decision. Retain event identity for deduplication and capture revision or availability metadata for temporal retrieval. Replaying events in sorted event-time order is a useful oracle for final aggregate values, but does not reproduce the original publication timeline by itself.
Watermarks govern progress under a declared policy
Flink 2.1 uses watermarks to represent event-time progress and drive event-time windows. A multi-input operator ordinarily advances with its relevant input watermarks; an idle source can hold progress back unless handled under the documented idleness policy. Bounded-out-of-orderness generation encodes assumptions about observed timestamps, not a universal proof that an arbitrarily late producer can never emit older data. Watermark alignment and idleness have operational effects, so validate behavior with the actual source connectors and deployment.
Allowed lateness controls how long eligible window state remains available for late updates in the specified operator. A trigger determines when outputs appear, while accumulation mode determines whether repeated panes contain cumulative values or newly accumulated pieces. Beam exposes these distinctions explicitly. Flink’s late firings can update a previous window result. If the downstream online writer adds every cumulative firing as though it were a delta, it double-counts. Encode entity, window, definition version, and revision identity so repeated results can be replaced or otherwise combined correctly.
Choose an explicit policy for data after cleanup
After a window’s retained state expires, the system needs a policy for later data: discard with metrics, route to a side output, rebuild affected buckets, or run a separate correction path. Silently allowing final offline recomputation to include all events while online serving permanently drops some creates a parity gap. Measure lateness distributions by source and entity class, because one global percentile can hide a producer with chronic delays. Keep enough source history to support whichever correction or audit policy you promise.
The queue instrument illustrates processing pressure rather than event-time semantics. Reset, set both λ=4 and μ=3, predict backlog six at t=2 from the initial four, then Step four times. Separately Reset, set both λ=2 and μ=3, predict drainage at t=4, then Step eight times. This deterministic fluid backlog has no event timestamps, watermark, window membership, or late firing. It demonstrates that a service-rate deficit can accumulate work; interpreting that count as a measured watermark delay would require information the model does not contain.
Work it through
A boundary event and a late correction
A ten-minute sum at 12:10 uses [12:00,12:10). Three deduplicated events have timestamps and amounts (12:00,3), (12:08,7), and (12:10,11). A later arrival describes an additional event at 12:05 with amount 5.
The first two events are in the half-open interval, giving 3+7=10. The event exactly at 12:10 is excluded from this window and must not add eleven to its sum.
If the late 12:05 event is accepted by the correction policy, the corrected window sum is 10+5=15. A cumulative revision should replace the earlier published ten rather than be added to it.
The corrected value fifteen was not necessarily available at 12:10. A historic as-known training join must use the publication/availability history, while a corrected-truth query can deliberately use the revised aggregate.
Membership, corrected aggregate value, and historic serving availability are separate properties even when they refer to the same event-time interval.
The living notebook
Explore the model
Interactive lab · queue
Backlog is not a watermark
Reset, set both λ=4 and μ=3, predict backlog six at t=2, then Step four times. Separately Reset, set both λ=2 and μ=3, predict backlog zero at t=4, then Step eight times. The initial backlog is four and each Step advances 0.5s; this fluid model contains no event-time windows or watermark logic.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forKeep processing-capacity evidence separate from event-time and lateness guarantees.
Pause & reason
Check your understanding
Your turn
Try it yourself
A fifteen-minute half-open window is [09:45,10:00). Events of amounts 2, 4, and 8 occur at 09:44, 09:45, and 10:00. What is the event-time sum?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Apply both interval boundaries exactly.
Compare with the solution
Only the 09:45 event belongs, so the sum is 4. The 09:44 event precedes the lower bound and the event at 10:00 equals the excluded upper bound. Availability, deduplication, allowed lateness, and the time the result was published are additional checks beyond this membership arithmetic.
Keep the idea
Take it with you
- Define exact event-time intervals before triggers and publication timing.
- Watermarks and lateness encode progress and retention policies.
- Make repeated window results explicit revisions or explicit deltas.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.