Durable execution

On this page 7

Durable execution is a programming and runtime model in which the state and progress of a running workflow are persisted automatically, so that the code resumes from the exact point of interruption after a crash, deployment, network failure or long wait. In reliability engineering for automation, it moves fault tolerance from hand-written retry and recovery code into the execution platform itself.

With durable execution, a developer writes ordinary sequential code, for example charge a card, reserve stock, wait three days, send a reminder, and the runtime guarantees that each completed step is never lost and never silently repeated. The model underpins workflow engines such as Temporal, Cadence, Restate and cloud durable functions, and it is increasingly used for long-running AI agents that must survive failures between tool calls.

How durable execution preserves progress

Durable execution relies on an append-only event history that records every meaningful step of a workflow. When a worker process fails, another worker loads the history and replays the workflow code, skipping the side effects that already happened by returning their recorded results. The code then continues with the first step that has no recorded outcome.

  1. The workflow calls an activity, a unit of work with side effects such as an API call.
  2. The runtime records the scheduling of the activity and, later, its result in the history.
  3. A crash interrupts the worker before the next step begins.
  4. A new worker replays the workflow from the history and reaches the same point.
  5. Execution continues as if nothing had happened, without calling the completed activity again.

Some engines use journaling per step instead of full replay, or combine both with snapshots. The underlying principle is identical: progress is stored in durable storage before the program moves on, so the in-memory state becomes disposable.

Building blocks and their guarantees

A durable execution platform exposes a few primitives that together provide exactly-once workflow logic over at-least-once infrastructure. The table lists the main primitives and what each guarantees.

PrimitivePurposeGuarantee
WorkflowOrchestrates steps in deterministic codeSurvives process and host failures
Activity or stepPerforms side effectsResult recorded once it succeeds
Durable timerWaits for minutes, days or monthsFires even after restarts
Signal or eventDelivers external input to a workflowPersisted before it is processed
Retry policyRepeats failed activitiesApplies backoff and limits automatically
QueryReads current workflow stateConsistent with recorded history
Core primitives of durable execution

Activities run with at-least-once semantics, because a worker can crash after an external system completed the call but before the result was recorded. Idempotency keys on activities are therefore still required for payments, emails and other non-repeatable effects.

Durable execution compared with other reliability techniques

Durable execution does not replace every reliability pattern; it absorbs several of them into the runtime. The comparison shows how it relates to techniques that teams traditionally implement themselves.

ApproachWhere state livesMain burden on developers
Durable executionEvent history in the platformDeterministic workflow code
CheckpointingPeriodic snapshotsChoosing checkpoint frequency and restore logic
Queues with retriesMessages and a dead letter queueChaining steps and tracking progress
Saga patternApplication databaseCoordinating steps and compensating actions
Transactional outboxOutbox tableReliable event publishing only
Cron plus status tableCustom status columnsPolling, locking and recovery code
Durable execution and related reliability patterns

Sagas and compensating actions remain relevant, but within durable execution they become plain try and catch logic in workflow code, because the runtime guarantees that the compensation path itself will run to completion.

Determinism and workflow versioning

Replay only works when workflow code is deterministic: given the same history, it must make the same decisions in the same order. Any non-deterministic call inside workflow code breaks replay and can leave a workflow stuck in an error state.

Forbidden in workflow codeReasonSafe alternative
System clock readsValue differs on replayPlatform-provided workflow time
Random numbersValue differs on replayPlatform random or an activity
Direct network or database callsSide effects repeat or changeWrap the call in an activity
Iterating unordered mapsOrder can changeSort keys before iterating
Native threadsScheduling is unpredictablePlatform coroutines or child workflows
Determinism rules for workflow code

Changing code while thousands of workflows are mid-flight requires explicit workflow versioning. Engines provide version markers or patch APIs so that old executions follow the old branch during replay while new executions follow the new one. Skipping this step is the most common cause of production incidents with durable execution.

When to use it and its limitations

Durable execution delivers the most value for long-running, multi-step processes with external side effects, such as order fulfillment, onboarding, infrastructure provisioning, payment flows and AI agents that call many tools. For a single stateless request, it adds overhead without benefit.

  • Latency overhead arises because every step writes to durable storage before continuing.
  • History growth in very long workflows requires techniques such as continue-as-new.
  • Operational dependency on the platform cluster or managed service becomes critical.
  • Learning curve around determinism and versioning slows early adoption.
  • Payload limits mean large data should be stored externally and referenced by key.

Teams adopting the model should start with one well-bounded process, add workflow monitoring and replay tests to the CI pipeline, and establish versioning conventions before the first production deployment.

A plain-language summary

Durable execution works like a video game that saves after every move. If the power goes out, you do not start the level again. You load the save and continue from the last step you finished.

For software, this means a long process, such as handling an online order over several days, cannot be lost halfway. The system writes down each completed step. After a failure, it reads its notes and picks up exactly where it stopped, without doing finished steps twice.

An example from practice

An online subscription service handles sign-ups with a durable workflow. The workflow creates the account, charges the first payment with an idempotency key, provisions access, sends a welcome email and then waits 14 days on a durable timer before checking whether the customer has used the product and sending a tailored follow-up.

During a routine deployment, all workers restart while about 20,000 sign-up workflows are in progress, many of them in the middle of their 14-day wait. After the restart, the workflows resume from their histories. No customer is charged twice, no welcome email is duplicated, and every follow-up message is sent on the correct day, without a single line of custom recovery code.