Event Streaming LabPython · Bytewax

Chapter 30 · Real process recovery

Recover after a failure

The write succeeded. The offset did not.

Prerequisite When is it safe to forget?.

What you’ll learn

Verify that a killed Bytewax process restores a source position and keyed state, and identify what this does not guarantee.

The question

A process vanishes after processing three values. Restarting at the beginning would repeat those values. Restarting only the source while losing its running total would produce the wrong answer. The recovery configuration must restore them together.

A checkpoint saves the running totals and the next source position together. A controller waits for Bytewax to record a completed checkpoint in SQLite, stops the engine immediately with SIGKILL, adds two more amounts and starts another engine. Both engines run inside one experiment and can see its checkpoint files.

Restore state and source position from one completed checkpoint
  1. Completed checkpointSum 25 · next position 3The drill observes completion before the crash.
  2. FailureSIGKILLThe engine process actually stops.
  3. New processRestore the checkpointSource position and state resume together.
  4. New input7 and 4 → total 36Ordinary output is not a transactional sink.

Conceptual diagram. The whole drill stays inside one guest. Closing the browser loses this temporary recovery database.

Predict the result

Five amounts arrive as £12, £8, £5, £7 and £4. The controller gives the original process its first three inputs, waits for a completed checkpoint and kills it. The restart either restores that checkpoint or reads from the beginning.

The first process reads 12, 8 and 5, reaching 25. After restart it sees 7 and 4. What source position and total must be restored to finish at 36?

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.

{
  "checkpoint": true,
  "resumed_from": 3,
  "restored_total": 25,
  "outputs": [
    12,
    20,
    25,
    32,
    36
  ],
  "replayed_records": 0,
  "final_total": 36,
  "boundary": "SIGKILL and process restart in one guest; volatile filesystem; ordinary non-transactional output."
}

Read the result

Read resumed_from, restored_total, and outputs and check whether the restarted process repeats any input. The controller killed the original process after confirming a completed checkpoint.

Change the experiment

Replace checkpoint=True with checkpoint=False in the editor. Select Run again. Compare resumed_from, restored_total, replayed_records, and outputs. Both runs finish at the same sum. Which evidence reveals that the second process started over?

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.

Locate the tested failure boundary

The controller stops the process after a completed checkpoint. The result shows how that restart recovers source position and state. Testing a crash between a write and the next completed checkpoint would require controlling a different failure point.

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 engine updates a scalar per input and writes recovery state. The controller polls SQLite, observes completion, kills and starts an actual engine process.
StateSource position and keyed state are stored in a recovery DB. The second engine can see the input and output files because it starts inside the same run.
MovementProcess creation, SQLite I/O and a local output file are real. There is no external transactional sink or replicated checkpoint store.
ProgressThe kill is delayed until a completed checkpoint exists. Restart restores position 3 and total 25 before processing the final two records.
RecoverySIGKILL recovery is verified at the chosen checkpoint. These files are private to the run. A crash between an output write and its checkpoint can duplicate ordinary output on replay.

Think it through

If the process is killed after a visible sink write but before that write is represented by a completed checkpoint, can this ordinary output file prevent a duplicate effect?

Show hints
  1. Hint 1

    The output file is separate from Bytewax recovery metadata.

  2. Hint 2

    Our controlled crash waits for a completed checkpoint.

  3. Hint 3

    A stronger claim needs a transactional or idempotent sink contract.

Show explanation

No. A process checkpoint alone does not atomically commit an arbitrary external effect. This drill verifies source and state restoration at a controlled completed checkpoint. An uncontrolled write/checkpoint race needs sink-specific coordination or idempotency and another failure experiment.

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 experiment stops and restarts a real Bytewax process with a file source and a SQLite checkpoint. The checkpoint files are private to the run and disappear before another run. The output uses ordinary file appends. Exactly-once external effects require a separate experiment with the actual destination.

Primary reference →
Reading marks track what you’ve read independently of your runs.