Event Streaming LabPython · Bytewax

Chapter 39 · Fluid capacity model

Budget for recovery

Normal capacity is not recovery capacity.

Prerequisite Where does the waiting go?.

What you’ll learn

Compute catch-up headroom and identify costs excluded from a recovery estimate.

The question

The service normally accepts 80 events per second and processes 100. A five-second outage builds a backlog. Restoring the process is not the same as restoring timely service.

Under constant rates, an outage creates offered rate × outage duration unfinished events. After restart, only service minus continuing offered load is available to drain that backlog. This assumes the source retains all work, service immediately returns to the stated rate, and no records are dropped. State restore time, checkpoint replay and sink retries are extra costs.

Recovery needs headroom above new arrivals
  1. OutageBacklog accumulatesRetained work must still be available.
  2. RestartNew arrivals continueNormal workload has not paused automatically.
  3. HeadroomCompletion minus arrivalsPositive headroom drains the backlog.
  4. Caught upFreshness restoredEqual rates cannot drain a positive backlog.

Conceptual diagram. This is a labelled fluid capacity model. The actual deployment needs measured rates and retention evidence.

Predict the result

The model uses a five-second outage, 80 arrivals per second and processing capacity of 100 events per second after restart. It assumes every record is kept during the outage.

A 400-event backlog and a 100-event/s service: does the system catch up in four seconds while new events continue arriving?

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.

{
  "backlog_at_restart": 400,
  "spare_per_second": 20,
  "catch_up_seconds": 20,
  "can_catch_up": true,
  "note": "Constant-rate fluid model. No state restore time, retries or further outage included."
}

Read the result

Read backlog_at_restart, spare_per_second, and catch_up_seconds. The outage leaves 400 events waiting. Arrivals continue at 80 events per second after restart, leaving only 20 per second to clear that backlog.

Change the experiment

Replace service=100 with service=80 in the editor. Select Run again. Then replace service=80 with service=120 and select Run again. Compare spare_per_second, can_catch_up, and catch_up_seconds. Why does the result report null instead of a duration at equal rates?

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.

Plan a workload envelope

An average arrival rate hides bursts and key skew. A sink’s quota can constrain recovery even when CPU is free. Retention must exceed the time needed to discover, restore and catch up from the failure; otherwise replayable source data may disappear before the job reaches it.

A recovery report needs correctness evidence

After a drill, inspect duplicates, missing IDs and the final state alongside time to restart and time to catch up. A fast recovery that silently resets offsets or drops old work does not meet the same objective as a complete recovery. Declare any intentional loss policy before comparing systems.

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
WorkO(1) arithmetic for the fluid formula. This is not the work performed by a recovery engine.
StateO(1) model state. Actual retained backlog, snapshots and sink transactions can dominate storage.
MovementThe calculation represents backlog with an event count and uses constant input and service rates.
ProgressOnly service capacity above continuing arrivals reduces the modeled backlog.
RecoveryThe estimate starts when service returns. Measure the time to restore state and restart processing separately.

Think it through

Would increasing checkpoint frequency necessarily reduce the total recovery disruption?

Show hints
  1. Hint 1

    More recent checkpoints can reduce replay, but checkpoints also consume resources.

  2. Hint 2

    Restore time and the spare service rate still matter.

  3. Hint 3

    Measure the transition, not just the last completed checkpoint age.

Show explanation

Not necessarily. It may reduce replay distance while increasing steady-state pressure and lowering recovery headroom. Include checkpoint cost, snapshot size, restore/warm-up time, replay volume, sink limits and the continuing arrival rate. Validate the objective using a real failure drill for the actual framework.

ReferencesFunction documentation and helper source

References open in a new tab; course helpers are documented separately from library APIs.

  • Recovery capacity and state size

    recovery_capacity computes a fluid capacity model. Compare its spare-rate assumption with actual restore, replay and state-loading costs.

  • 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

Constant-rate arithmetic is a planning reference, not an observed restart or an availability guarantee.

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