Event Streaming LabPython · Bytewax

Chapter 1 · Real Bytewax

Follow an event

From a record to a useful stream.

Prerequisite Basic Python lists, dictionaries, functions and lambdas.

What you’ll learn

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.

Follow what survives each operation
  1. InputFive ordersThe source contains more records than the final output.
  2. PredicateFilterOnly eligible orders continue.
  3. TransformationMapChoose the output record shape.
  4. 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.

Ctrl+Enter or ⌘+Enter runs the code.

Edits are saved in this browser when storage is available.

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?

Return to the editor
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.

QuestionMechanism and boundary
WorkThe filter tests its condition once for each input. The map runs once for each accepted record. With constant-cost functions, total O(n).
StateO(1) auxiliary operator state; this page collects output in O(n) memory.
MovementNo network exchange in the local pipeline. Payload serialization is a separate boundary.
ProgressCan emit as each retained record is handled.
RecoveryReplay 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
  1. Hint 1

    Separate arrival from selection.

  2. Hint 2

    Count the input records, then the output records.

  3. 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.

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 →
Reading marks track what you’ve read independently of your runs.