Separate occurrence time from processing time
A five-minute sales aggregate can receive events long after a terminal recorded them. Event time is the timestamp attached to occurrence; processing time belongs to the processing system. Read message histories and clock distinctions first. We vary arrival order while tracing window assignment, output and correction. An attached timestamp also depends on the source's clock contract rather than proving perfect physical time.
Use A at 10:01 for one hundred, B at 10:04 for two hundred and C at 10:02 for forty. All belong to event-time window [10:00,10:05), totaling 340. C arriving at 10:06 does not change that event-time membership. Processing-time windows can put C elsewhere. Choose according to whether the business asks about sales occurrence or work processed, rather than calling one clock universally correct for every aggregation.
Specify window membership and retained state
Use lower-inclusive, upper-exclusive five-minute intervals, so an event at 10:05 belongs to the next window. Retain aggregate state per key and window. State volume depends on key count, lateness policy and stored information, not just window width. Session windows introduce merging and termination rules beyond this fixed-window model.
After A and B arrive, the current sum is 300. Publishing it immediately creates a provisional result that may later change. Fast first output differs from fast final output. Carry window identity, version and correction semantics where needed. A receiver must not sum successive totals 300 and 340 into 640. Specify replacement, retraction or recomputation consistently at both ends. The input clock does not decide this output-update contract for you.
Interpret watermarks as progress under a policy
A watermark communicates event-time progress under a chosen generation rule and supports decisions about old input. It is not a universal mathematical proof that every earlier event has arrived. Delayed sources, pauses and bad timestamps can still produce older events. Check who generates progress and how multiple inputs combine under the selected system's documentation.
In our minute-resolution example, watermark 10:05 triggers the first result for [10:00,10:05): 300 while C is absent. A firing condition is not omniscience about input. Real APIs define timestamp granularity and window-end conventions, which must be matched when translating this table into code. Setting progress equal to current processing time also imposes an input-delay assumption. State that assumption rather than treating a convenient clock value as guaranteed event completeness.
Correct within retained lateness and define later arrivals
Allow two minutes after window end. If C arrives while watermark is 10:06 and state remains, add forty and emit corrected total 340. After cleanup beyond 10:07, an old-window event needs a declared policy: discard, side output or later recomputation. A lateness setting does not provide unlimited retrospective correction.
Let D be a value-four sale at 10:04 arriving after watermark 10:08. The normal retained-window result can stay 340 while an offline aggregation of all four events is 344. This can reflect an admission policy difference rather than arithmetic error. If complete sales are required, the product needs reconciliation and correction rather than silently accepting the difference. Preserve late-data evidence and define what revised output means to users. Fast processing and eventual completeness require compatible policies.
| Arrival or progress | Retained total | Output meaning |
|---|---|---|
| A and B arrive | 300 | Provisional state |
| Watermark 10:05 | 300 | Initial firing |
| C arrives at progress 10:06 | 340 | Within-policy correction |
| D arrives after cleanup | Normal path stays 340 | Side-output or recompute policy |
Handle idle and invalid-timestamp sources
In multi-input operators, one stalled input watermark can hold back combined progress. Marking an idle input can allow progress but needs a policy for old data after it resumes. Ignoring a source does not prove its complete delivery. Observe source state, progress, retained window count and oldest state. Low CPU alongside growing state can indicate progress blockage rather than insufficient arithmetic capacity.
A source reporting a far-future timestamp can also distort a maximum-based progress rule and make normal events appear late. Define plausible timestamp bounds and abnormal-input handling. Replacing timestamps with current time changes event meaning and must not be hidden. Completeness-sensitive workflows may additionally need source correction, replay and periodic reconciliation. A time model cannot by itself recover facts never sent or decide which source timestamp is truthful.
Separate replayed state from external output guarantees
Recovery can replay input and repeat outputs. Verify consistent state/input-position recovery and the destination's treatment of duplicate results. A watermark is not a deduplication ID. When a system documents exactly-once semantics, inspect whether the scope is internal state or a supported sink protocol. Do not extend it to arbitrary external notifications.
Updating a window ID with a new version can support replacement; appending each total to another sum can duplicate values. Test corrections and delivery retries separately. Compare reordered input, arrivals beyond retention and recovery effect counts as distinct cases. The worked table is not an executed Flink cluster failure test. A concrete implementation needs its own stated verification scope against the selected runtime and sink. This keeps conceptual progress rules separate from operational delivery claims.
Compare reordered arrivals under the same admitted event set
If A, B and C all arrive within retained lateness, orders A-B-C and C-A-B produce the same final window sum 340. Intermediate values differ. The second order might first expose forty, unless the output policy waits for another trigger. Test final aggregate equivalence separately from which provisional versions users can observe. If late-data admission changes, the pipelines no longer aggregate the same admitted input set, so equal final answers are not automatically required under the previous premise.
Retained event identity helps compare reordered input and retries as the same facts. Its deduplication lifetime is nevertheless a different policy from window-state retention. Decide what happens when a previously processed sale arrives after window cleanup: duplicate refusal, late side output or reconciliation can have different meanings. Align the identity scope with replay duration, not only the displayed window width. A retained source archive can support later reconstruction, but the sink must still treat revised totals as replacements or declared corrections. These distinctions give a practical checklist for reproducing the worked example: fix event identities and amounts, event-time membership, allowed arrival range, progress rule, state cleanup and output version semantics. Change one at a time and label the result. The comparison then tests a defined processing contract rather than treating any difference between two plausible-looking totals as an arithmetic defect.
When corrections are frequent, associate an observed output version with its replacement. Keeping only the latest total can hide why a downstream consumer counted twice or a user saw another value. Version history is diagnostic evidence, not another sale to add.
Solve the two late-arrival cases
With window end 10:05 and two-minute retention, C at progress 10:06 can update the retained result to 340. D after 10:08 needs the declared post-cleanup policy. If the application requires the complete 344 from all events, add reconciliation and revised-output semantics. Progress alone is not proof of complete arrival.
An event exactly at 10:05 belongs to [10:05,10:10), irrespective of arriving at 10:06. The learning outcome aligns occurrence, arrival, progress, retention and output version in one trace. The batch-versus-stream comparison next uses the same sales data to choose when results should be provisional, corrected or considered final.