Chapter 1 · Real Bytewax
Follow an event
From a record to a useful stream.
Prerequisite Basic Python lists, dictionaries, functions and lambdas.
Read an event record and explain which records a filter keeps.
The question
The bicycle shop wants a live view of larger orders. Before adding a broker or a dashboard, follow five small records through one pipeline.
An event records something that happened. Each order has an ID, shop, amount in pounds and the time of the sale in seconds. A Bytewax dataflow connects steps. filter keeps orders that meet a condition, then map selects the fields to return. The collect helper runs these steps and returns their output as a list.
- InputFive ordersThe source contains more records than the final output.
- PredicateFilterOnly eligible orders continue.
- TransformationMapChoose the output record shape.
- Observed outputa and eOutput count is different from input count.
Conceptual diagram. The starter source is bounded. Run executes the actual Bytewax operators; the diagram is an explanatory view.
Predict the result
Five orders arrive in the order a (£12), b (£8), c (£5), d (£7), e (£9). The editor imports them as ORDERS.
Which order IDs will survive a minimum amount of £9? Does filtering change their arrival order?
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.
[
{
"id": "a",
"pounds": 12
},
{
"id": "e",
"pounds": 9
}
]Read the result
The console lists id and pounds for each retained order. Find a and e in that order, then compare with the five input orders above. The filter keeps matching orders in this run and the map changes their fields.
Change the experiment
Replace order['amount'] >= 9 with order['amount'] >= 7 in the editor. Select Run again. Compare the output IDs and their order. Which amounts qualify at £7 that did not qualify at £9?
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.
Trace a discarded order
Order b still costs a predicate evaluation even though no output row is emitted. Track offered, retained and rejected counts separately. With the original threshold, five inputs produce two outputs. Optimizing a downstream stage does not remove the work already spent reading and checking the other three.
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 | The filter tests its condition once for each input. The map runs once for each accepted record. With constant-cost functions, total O(n). |
| State | O(1) auxiliary operator state; this page collects output in O(n) memory. |
| Movement | No network exchange in the local pipeline. Payload serialization is a separate boundary. |
| Progress | Can emit as each retained record is handled. |
| Recovery | Replay repeats transformations; effects downstream need their own retry contract. |
Think it through
If the downstream dashboard shows only two orders, can you conclude that only two orders arrived?
Show hints
Hint 1
Separate arrival from selection.
Hint 2
Count the input records, then the output records.
Hint 3
The filter rejects b, c and d at the original threshold.
Show explanation
Five arrived, and two met the filter condition. The output count alone cannot tell you the input count. Capture both the total input and the rejected records when investigating a real pipeline.
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.
Filter and transform each event
Read the predicate and mapper contracts: one decides which records continue; the other chooses the value emitted.
Build and execute a bounded dataflow
dataflow.Dataflow(new tab)op.input(new tab)testing.TestingSource(new tab)op.output(new tab)testing.TestingSink(new tab)testing.run_main(new tab)Follow the source, output and execution interfaces used by the editor and the course collect helper.
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 is a finite Bytewax TestingSource in one worker. The Kafka chapters add real protocol clients connected to an in-memory simulator. This source has no broker or durable log.
Primary reference →