Chapter 10 · Explicit clock model
Choose the right clock
The same order can belong to two different windows.
Prerequisite Expand and re-key a stream.
Use one order to explain why its event time and processing time can place it in different windows.
The question
An offline checkout sends its morning orders at lunchtime. A processing-time dashboard reports a lunchtime spike. An event-time dashboard reports morning sales—once it can decide how long to wait for missing data.
Event time describes when the order happened. Processing time describes when an operator handles it. The editor supplies invented processing times measured in seconds from the same starting point as the order times. Window 0 includes 0 and excludes 10. Window 1 starts at 10 and excludes 20.
Predict the result
The model supplies event times of 0, 12, 8, 3 and 25 seconds for orders a, b, c, d and e. The editor supplies their processing times. Each window is ten seconds wide.
Order c happened at event time 8 but is observed at processing time 13. Which ten-second window does each clock assign it to?
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.
{
"trace": [
{
"id": "a",
"event_time": 0,
"processing_time": 0,
"event_window": 0,
"processing_window": 0
},
{
"id": "b",
"event_time": 12,
"processing_time": 12,
"event_window": 1,
"processing_window": 1
},
{
"id": "c",
"event_time": 8,
"processing_time": 13,
"event_window": 0,
"processing_window": 1
},
{
"id": "d",
"event_time": 3,
"processing_time": 14,
"event_window": 0,
"processing_window": 1
},
{
"id": "e",
"event_time": 25,
"processing_time": 25,
"event_window": 2,
"processing_window": 2
}
],
"note": "Authored arrival clock; neither clock measures execution speed."
}Read the result
In the trace, use Next trace step until id is c, or find c in the console’s trace. Compare event_time and processing_time and read which windows these values select in event_window and processing_window.
Change the experiment
Replace "c": 13 with "c": 9 in the editor. Select Run again. Find c again. Compare event_window and processing_window with the first run. Which window changes when event time and the ten-second window rule stay fixed? The trace lists orders a through e in fixture order.
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.
Delay is a difference between named boundaries
Event age at queryability includes producer offline time, network transit, queueing and processing. Operator execution latency may include only a small part of it. Store multiple timestamps when diagnosing a delayed result and explain what uncertainty each clock introduces.
Separate disorder from skew
Out-of-order arrival can happen even with correct producer clocks because paths take different amounts of time. Clock skew can make the event timestamp wrong before transport starts. Watermarks encode an application progress policy; they do not establish clock accuracy or causal ordering between producers.
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 | O(n) assignments using constant-time integer arithmetic. |
| State | O(n) trace records; no online retention logic. |
| Movement | The input contains the timestamps for both clocks. The helper uses local arithmetic to assign windows. |
| Progress | The trace gives two membership assignments per order. A live window would need a separate rule for when to emit. |
| Recovery | Keep the timestamp origin and rule with the fixture so later runs can reproduce the assignments. |
Think it through
Suppose a watermark uses the greatest event timestamp seen so far minus a fixed wait. This marker tells the system how far event time has progressed. What can happen if a producer sends a timestamp a year in the future?
Show hints
Hint 1
The maximum timestamp influences every subsequent watermark.
Hint 2
Monotonic progress generally cannot be rewound to rescue older windows.
Hint 3
Validation belongs before advancing time from untrusted timestamps.
Show explanation
It can advance progress far beyond legitimate records, closing windows and classifying later normal arrivals as late. Validate plausible timestamp ranges, units and clock origins; quarantine suspicious records before they drive progress. A large out-of-order allowance is not a general cure for a bad clock.
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.
Engine clock contract for comparison
clock_windows is an authored assignment model. These engine clocks show how event timestamps and system time are selected in an actual window operator.
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
This authored model assigns a fixed set of orders to windows. Processing times are inputs to the model. No latency is measured and no broker assigns the timestamps.
Primary reference →