Chapter 13 · Bytewax EventClock
Wait for late events
Trade a faster answer for a more complete one.
Prerequisite Merge a session.
Explain a watermark, route late events, and identify the latency/state tradeoff.
The question
A mobile checkout uploads an order late. A window has already closed without it. The sales dashboard is consistent with arrival order, but disagrees with when the sale happened.
A watermark estimates how far event time has progressed. Bytewax uses that marker to decide when windows can close and whether an arriving record is late. The wait setting gives out-of-order records time to arrive. In this run, a fixed wall clock lets you see how input timestamps affect progress. The result includes both the records accepted into windows and those sent to the late output.
- Window outputAccepted membersThe real window operator emits the bounded result.
- Late side outputToo-late recordsInspect these separately from accepted window members.
Conceptual diagram. A later arrival can describe an earlier event. Run provides the execution trace below. The frozen wall clock makes this fixture repeatable, not a latency benchmark.
Predict the result
The five event times arrive as 0, 12, 8, 3 and 25 seconds. The editor selects the clock’s five-second wait. Wall time is frozen.
Arrival timestamps are 0, 12, 8, 3 and 25. With a five-second wait, will order d at time 3 still be accepted?
Run the experiment
The editor contains the published example. Select Run with the code unchanged.
Python prepares in the background while you read. First use can download about 84 MiB. Your code runs only when you select Run; each run starts with clean experiment state.
A saved draft is open. Select Restore code to see the published example. Recover draft brings back your draft.
Ctrl+Enter or ⌘+Enter runs the code.
Edits are saved in this browser when storage is available.
Technical error details
Your result
Console output
Troubleshooting
If Python stops responding, restart the environment and try again. Your code and last completed result are kept.
View the published result
The course build ran the published code to generate this output.
{
"windows": [
{
"window": "[0, 10)",
"ids": [
"a",
"c"
],
"total": 17
},
{
"window": "[10, 20)",
"ids": [
"b"
],
"total": 8
},
{
"window": "[20, 30)",
"ids": [
"e"
],
"total": 9
}
],
"late": [
"d"
],
"trace": [
{
"emission": "closed window",
"window": "[0, 10)",
"ids": [
"a",
"c"
],
"total": 17
},
{
"emission": "closed window",
"window": "[10, 20)",
"ids": [
"b"
],
"total": 8
},
{
"emission": "closed window",
"window": "[20, 30)",
"ids": [
"e"
],
"total": 9
},
{
"emission": "late side output",
"id": "d"
}
],
"boundary": "Real Bytewax EventClock; frozen wall clock; EOF flushes open windows."
}Read the result
Find order d in late. In windows, find the first row’s ids and total. Bytewax reports accepted records in event-time order for each emitted window. The source ends and the engine emits any open windows.
Change the experiment
Replace wait=5 with wait=30 in the editor. Select Run again. Compare late and the first window’s ids and total. Which additional order contributes to the first window?
Runtime, source code and downloads
Runtime and reset details explain what stays ready and what is isolated on each run. Download Python packages the published helpers with the code in your editor.
Browse the sources for Bytewax windows and authored models, Kafka log and group exercises, live Kafka input, checkpoint recovery and processing patterns.
Separate the first emission from cleanup
This introductory helper uses a strict timestamp-below-watermark rejection rule. The later correction chapter deliberately uses another policy: retain a previously emitted window and publish revisions until cleanup. Neither policy is universal. Always state the timestamp, progress, retention and output rules together.
Work, state and recovery costs
Where used, n counts input events, k counts retained distinct keys, r counts overlapping windows per event and z counts output matches. Bounds assume the stated algorithm. Collecting, sorting and displaying results adds work.
| Question | Mechanism and boundary |
|---|---|
| Work | Each record is timestamped and considered by the real Bytewax window operator. Cost depends on open windows and collector size; the diagnostic trace is emitted output. |
| State | Accepted open-window records, late outputs and collected results. A larger wait generally retains more event history; it is not free completeness. |
| Movement | One local worker with a TestingSource. Multiple-input watermark coordination and network barriers are advanced reading topics. |
| Progress | The actual late side output reports rejection. EOF flushes open windows. No internal watermark metric is invented for the trace. |
| Recovery | Replaying with a different wait can change accepted membership. Record the policy and source fixture with the output. |
Think it through
Does increasing the wait guarantee that every real-world event will be accepted?
Show hints
Hint 1
Our fixture is finite. A production delay might not be.
Hint 2
A bound on observed delay is an assumption.
Hint 3
Consider an offline device returning tomorrow.
Show explanation
No finite wait guarantees all possible arrivals. A larger wait delays final results and retains more state. Choose an explicit policy for very late data: discard, side output, or corrections. This lab uses a late list rather than silent loss.
ReferencesFunction documentation and helper source
References open in a new tab; course helpers are documented separately from library APIs. Bytewax links target the official 0.21.1 definitions and API docstrings.
Watermark progress and late output
Read the clock waiting duration and the window operator’s down and late outputs.
Course helper implementation
These are functions written for this course, not additional library APIs. Inspect their parameters, operator calls and authored policies. The source shown is generated from the same Python files packaged with Run and Download Python.
Experiment scope
These are actual Bytewax windows and late outputs in one worker. The frozen clock makes a bounded replay repeatable; it does not simulate multiple-input watermarks or prove that a particular wait bounds all real-world delays.
Primary reference →