Event Streaming LabPython · Bytewax

Chapter 31 · Reading

What makes a snapshot consistent?

A moving system needs a coordinated cut.

Prerequisites Recover after a failure; Where does a key live? Find chapters in the course contents.

What you’ll learn

Explain aligned checkpoint barriers across two inputs and the meaning of a completed checkpoint.

The situation

North’s total is 17 in one snapshot, but its source position says only the £12 order was consumed. On restart the £5 order is read again. Every individual file can be valid while the combined snapshot is inconsistent.

Choose one recoverable cut

A distributed checkpoint ties source positions to operator state and, where supported, sink progress. The cut must account for records before and after that boundary. Capturing each task at an unrelated wall-clock instant does not establish consistency.

A barrier travels through a dataflow in order with its channel’s records. For an aligned checkpoint, an operator that sees the barrier on A stops consuming post-barrier A data while it waits for the corresponding barrier on B. It can still process pre-barrier B data needed to complete the cut.

Follow two channels

Suppose a contributes £12 on A and b contributes £8 on B before barrier C. The task processes a, sees C on A, and then receives b on B. b belongs before the cut and must update state before the snapshot is finalized. A later c on A must not leak into C’s state.

Once the required barriers arrive, the operator establishes its snapshot boundary and can resume post-barrier work while snapshot material is persisted according to the implementation. A checkpoint is completed only when the coordinator has the required successful acknowledgments. Files from an abandoned attempt are not a completed restore point.

Worked case

Use the arrival order in the table to decide whether a, b and c are part of checkpoint C. In practice, saving a snapshot can continue while the job runs. The coordinator declares when a checkpoint is complete.

StepChannel AChannel BOperator action
1a · £12WaitingState = 12
2Barrier Cb · £8 still before CAlign A; process b; state = 20
3c · £5 after CBarrier CSnapshot state 20 at C
4Resume cPost-C workLive state becomes 25; C still represents 20

The implementation changes the cost

Unaligned checkpoints can include in-flight channel data to avoid waiting for all queues to drain into an aligned cut. That moves part of the cost into channel-state capture and restore; it is not free and does not remove every source of checkpoint delay.

A savepoint is an explicitly retained, user-triggered state snapshot used for controlled operations such as upgrades. Its lifecycle and compatibility concerns differ from routine checkpoints. For either, operator identity, state schema and redistribution compatibility matter when restoring changed code.

Think it through

If the sink has written c but the last completed checkpoint is C, can you restore C and safely append all replayed output?

Show hints
  1. Hint 1

    c belongs after C and will be processed again.

  2. Hint 2

    Checkpoint consistency inside the engine is only one part of sink correctness.

Show explanation

Not for a non-idempotent append sink without coordination. Restoring C replays post-C work, including c. The sink needs a transactional commit protocol, idempotency/deduplication, or a tolerance for duplicate effects. The next chapter follows that boundary.

How frameworks implement this

Flink checkpoints coordinate a distributed dataflow and can use aligned or unaligned mechanisms. Spark Structured Streaming recovery is organized around its execution mode, checkpoint logs and state; a Spark checkpoint directory should not be explained as the same barrier algorithm. Kafka offset commits alone do not snapshot arbitrary operator state.

ReferencesPrimary sources for this chapter’s design case

Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.

This mark tracks what you’ve read.