Highlights

Contents

Part VII
07

Checkpoints and exactly-once

We restore a consistent computation after failure. Saving state or committing offsets alone leaves an ambiguity. We will trace checkpoints, duplicate effects, sink coordination, and bounded recovery capacity.

CHAPTER ATLAS / FOLLOW THE READING PATHCHAPTER ATLAS / FOLLOW THE READING PATH1OLTP vs OLAP2Batch processing3Stream processing4Event time, windows,watermarks5ETL, ELT, warehouses, andlakes6CDC and materializedviews7Checkpoints andexactly-once8Spark and Flink9Case study: score toreport

#Section 25Save state with source progress

The processor has consumed records a and b and holds total 5. A checkpoint captures a recoverable combination of operator state and source positions. In the tiny input, the completed position is offset 1 when offsets start at zero. The checkpoint stores that position and state 5.

After a crash, restore both, then read c and d at offsets 2 and 3. Their values 4 and 1 add 5, giving the correct total 10. Restoring state 5 while starting again at offset 0 repeats a and b. Starting at offset 2 with empty state loses them. Consistency lies in the pair.

A CHECKPOINT RESTORES BOTH STATE AND THE MATCHING INPUT POSITIONA CHECKPOINT RESTORES BOTH STATE AND THE MATCHING INPUT POSITION0: 21: 32: 43: 1checkpoint boundaryposition: 1state: 2 + 3 = 5restore the pair5 + 4 + 1 = 10replay the tail after the checkpoint, not the covered prefix
Figure 17.25Computed illustrative checkpoint and restore trace. Source position convention is explicitly zero-based.

Under an illustrative thirty-second checkpoint interval, twenty events per second can require replaying up to six hundred recent events from the last completed checkpoint in the simplified exercise. That is 120,000 payload bytes. A checkpoint that takes time or fails can increase the gap, so the interval alone is not a strict recovery-work bound.

#Section 26Barriers coordinate distributed state

A pipeline has several inputs and stateful operators. A consistent checkpoint must avoid a combination where one operator includes a message another operator has not yet represented under the chosen protocol. A checkpoint barrier is a marker used by some engines to organize a distributed snapshot boundary in the flowing data.

Operators coordinate the boundary across inputs and record state according to the engine’s alignment or channel-state mechanism. Aligned and unaligned approaches have different backpressure and snapshot-cost tradeoffs. The concept is a consistent recoverable cut, not a demand that every machine stop at one wall-clock instant.

A BARRIER FLOWS WITH THE DATA; EACH OPERATOR SNAPSHOTS WHEN IT PASSESA BARRIER FLOWS WITH THE DATA; EACH OPERATOR SNAPSHOTS WHEN IT PASSESsource positions + every operator's state at the same logical cuta consistent cut is not one wall-clock instant
Figure 17.26Illustrative checkpoint coordination. The engine’s protocol determines channel treatment and snapshot completion.

A checkpoint completes only when every required snapshot component is durably available according to the protocol. One worker writing its state does not establish job-wide completion. A failed attempt can leave partial checkpoint data that must not be selected for restoration. Retain a known completed generation until the replacement is fully committed.

Flink’s stateful-processing documentation describes coordinated snapshots and restoring state with source positions. These guarantees depend on configured checkpointing and compatible sources. A framework name alone does not tell us whether a particular job has its recovery mechanism enabled or correctly stored.

#Section 27Exactly-once state is not every external effect

Record c adds 4. A crash occurs after an external sink applies that addition but before the job records completion. Replay applies c again, giving an incorrect total 14 instead of 10 in the tiny sequence. A consistent internal state checkpoint does not automatically roll back an unrelated external write.

At-least-once processing permits repeated processing after uncertain completion. Exactly-once state semantics means recovered operator state reflects each accepted input once under the engine’s protocol. End-to-end exactly-once effects also require compatible source and sink behavior around that protocol.

REPLAYING c AGAINST AN EXTERNAL ADDER TURNS 10 INTO 14REPLAYING c AGAINST AN EXTERNAL ADDER TURNS 10 INTO 14correct2341= 10replayed c23441= 14operator state may be exactly-once; the external sink is not unless the effect has an identity
Figure 17.27Computed illustrative duplicate-effect trace. Internal recovery does not by itself undo an external addition.

An idempotent keyed sink can overwrite a result version instead of adding twice. A transactional sink can coordinate output publication with checkpoint completion. A target transaction can record input identity with its effect. Choose a compatible mechanism and state its limits, especially when output is email, an API call, or another irreversible action.

#Section 28Recovery must outrun new input

The job has twelve thousand waiting records after an outage. Input continues at twenty per second. With one hundred twenty processing capacity per second, net catch-up is one hundred and recovery takes 120 seconds. At twenty capacity, it never drains; at less than twenty, lag grows further.

Recovery headroom is spare processing and downstream capacity available beyond ongoing demand. It includes state restoration, replay, sink writes, and any background compaction or maintenance. A healthy steady-state rate does not establish a useful outage recovery time.

12,000 BEHIND, 120/S PROCESSED, 20/S ARRIVING: 100/S NET, 120 S TO CATCH UP12,000 BEHIND, 120/S PROCESSED, 20/S ARRIVING: 100/S NET, 120 S TO CATCH UP12,0000 at 120 s120 − 20 = 100/srecovery headroom is capacity beyond the ongoing load; restore time is extra
Figure 17.28Computed illustrative catch-up duration under constant rates. Real restore time and sink bottlenecks are additional.

Heron’s illustrative thousand state keys at sixty-four bytes each occupy 64,000 bytes before runtime overhead. A thirty-second snapshot would write an average 0.002133333 MB per second if it rewrote only that raw state. Real checkpoint formats, metadata, incremental state, and storage latency can change the cost. Keep the raw count and measurement separate.