Checkpointing

On this page 7

Checkpointing is the practice of persisting the progress and state of a running workflow, batch job or data pipeline at defined points, so that after a crash, timeout or deployment it can resume from the last saved point instead of starting again from the beginning. In automation reliability, it is the mechanism that turns a long, fragile run into a sequence of recoverable steps.

A checkpoint records enough information to continue correctly: which steps have completed, which items were processed, the values of relevant variables and a position marker such as an offset, page token or record identifier. Combined with idempotent steps and a retry policy, checkpointing keeps failures cheap and prevents both lost work and duplicate work.

How checkpointing works in automated workflows

Checkpointing works by writing a durable state record after a unit of work is complete and reading it back when the run restarts. The restart logic loads the latest checkpoint, skips what is already done and continues with the next unit.

  1. Define the unit of work, such as one record, one batch of 500 rows or one workflow step.
  2. Perform the work and confirm that its side effects succeeded.
  3. Write the checkpoint to durable storage, ideally atomically with the work itself.
  4. On restart, read the checkpoint and resume from the recorded position.
  5. Clean up old checkpoints once the run completes successfully.

The ordering of steps two and three is the core design question. If the checkpoint is written before the work, a crash in between skips an item. If it is written after, a crash in between repeats an item. Most systems choose the second order and make the step idempotent, which yields at-least-once processing with safe repeats.

What a checkpoint contains

A checkpoint must hold the minimum state needed to resume correctly, and nothing that can be cheaply recomputed. Overly large checkpoints slow every save and complicate schema changes.

ElementExamplePurpose
Run identifierJob run ID or workflow instance IDTies the state to one execution
Position markerOffset 48,000 or last processed IDSays where to continue
Completed stepsSteps 1 to 4 doneAvoids repeating finished work
Working variablesRunning totals, tokens, file namesRestores context for later steps
External referencesIDs of created recordsSupports compensation or reconciliation
Timestamp and versionSaved time and code versionDetects incompatible resumes
Typical contents of a checkpoint

The code version field is easily forgotten. If a workflow definition changes between the failure and the restart, an old checkpoint may describe steps that no longer exist, and resuming blindly can corrupt data. A version check forces an explicit decision to migrate, replay or abandon the run.

Choosing the checkpoint interval

The checkpoint interval is a trade-off between overhead and rework. Frequent checkpoints add write cost to normal runs; rare checkpoints mean more work is repeated after each failure.

GranularityOverheadRework after failureTypical use
Per recordHighAt most one recordPayments, irreversible actions
Per batchModerateOne batch, often 100 to 10,000 itemsData synchronization, imports
Per workflow stepLowOne stepMulti-step business workflows
Time-basedPredictableWork since last intervalStream processing, long computations
Per run onlyMinimalThe entire runShort jobs of a few minutes
Effect of different checkpoint granularity

A practical rule is to size intervals so that the rework after a failure stays well below the job’s tolerance. If a nightly import must finish within a two-hour window, losing half an hour to a restart is acceptable, while losing ninety minutes is not.

Checkpointing is one of several techniques that make automation survive failures, and it works best in combination with them.

TechniqueQuestion it answersRelationship to checkpointing
Retry policyShould a failed step run againRetries happen within a checkpointed step
IdempotencyIs repeating a step safeMakes resume after checkpoint safe
Workflow replayCan state be rebuilt from historyReplaces explicit checkpoints with an event log
Saga patternHow to undo partial workUses checkpoint data to compensate
Dead letter queueWhere do failing items goLets a run continue past bad items
Job heartbeatIs the job still aliveTriggers recovery from the last checkpoint
Checkpointing and neighboring techniques

Durable workflow engines often implement checkpointing implicitly: they record every completed activity in an event history and rebuild state by replaying it. The effect is the same, but the developer must then write deterministic workflow code, because replay re-executes the logic against recorded results.

Pitfalls in implementing checkpointing

Checkpointing fails most often at the boundary between saved state and external side effects. The state says one thing, the target system says another, and the restart trusts the wrong one.

  • Non-atomic saves: the work commits but the checkpoint write fails, causing a repeat on non-idempotent steps.
  • Volatile storage: checkpoints kept in memory or on a temporary disk vanish with the failure they should survive.
  • Unstable ordering: resuming by offset on a source whose order changes skips or repeats records; use a stable key instead.
  • Expired tokens: saved pagination or session tokens may no longer be valid at restart time.
  • Never-tested recovery: restart logic that has never been exercised often fails when it is needed.
  • Unbounded growth: old checkpoints accumulate without a retention rule.

The most effective safeguard is to test recovery deliberately by killing jobs at random points in a test environment and verifying that the final result matches an uninterrupted run.

Put simply

Checkpointing is like saving your progress in a video game. If the power goes out, you restart from the last save instead of the very first level.

An automated job does the same thing: after each piece of work, it writes down how far it got. When something breaks, it reads that note and continues where it stopped, so hours of work are not lost and nothing is done twice by mistake.

In practice

A logistics company runs a nightly workflow that synchronizes about 400,000 shipment records from its warehouse system to a customer portal through an API limited to a few hundred calls per second. The full run takes roughly three hours, and occasional network failures used to force a complete restart that pushed the job past the morning deadline.

The team adds checkpointing per batch of 1,000 records. After each batch is confirmed by the API, the workflow stores the last shipment ID and the run ID in a database table in the same transaction as its own bookkeeping. Updates use upserts keyed on the shipment ID, so a repeated batch is harmless.

When a failure now occurs, the scheduler restarts the job, which reads the checkpoint and loses at most one batch of work. The synchronization finishes on time even on nights with several interruptions.