Skip to main content
Workflows let you write long-running processes as ordinary code. If your server restarts mid-execution, the workflow picks up exactly where it left off — no message queues, no manual checkpointing.
const orderWorkflow = Workflow.make((orderId: string) =>
  Effect.gen(function* () {
    const order = yield* Workflow.step({
      name: "Fetch order",
      execute: fetchOrder(orderId),
    });

    yield* Workflow.sleep("24 hours");

    yield* Workflow.step({
      name: "Charge card",
      execute: chargeCard(order),
    });
  })
);

How durable execution works

Two primitives create durability boundaries in a workflow:
  • Workflow.step() — executes an effect and caches the result in Durable Object storage. On resume, the cached result is replayed without re-executing the effect.
  • Workflow.sleep() — persists the wake-up time and pauses the workflow. A Cloudflare Durable Object alarm fires at the scheduled time to resume execution.
Code between steps runs again on every resume, so keep it deterministic and side-effect-free. Only step results and sleep timings are persisted.

Execution modes

When the executor runs a workflow, it operates in one of three modes:
ModeWhen usedBehavior
freshFirst executionNo cached data — execute all steps
resumeAfter a sleep or retry delayReplay cached step results, continue from the pause point
recoverAfter an infrastructure failureSame as resume, triggered by the recovery system when a stale Running workflow is detected

Workflow state machine

Every workflow instance transitions through a defined set of states:
Pending → Running → Paused ⇄ Running → Completed
                  ↘ Failed
                  ↘ Cancelled
The full transition table:
StateValid next states
PendingRunning, Queued
QueuedRunning, Cancelled
RunningCompleted, Paused, Failed, Cancelled
PausedRunning, Cancelled
Completed— (terminal)
Failed— (terminal)
Cancelled— (terminal)
Paused workflows resume when their scheduled alarm fires. Running workflows that appear stale after a server restart are detected by the recovery system and re-executed in recover mode.

Steps

Cache results and build the core logic of your workflow

Sleep

Pause for seconds, hours, or days across restarts

Retry and timeouts

Configure backoff strategies and per-step deadlines

Cloudflare setup

Wire up Durable Objects bindings and wrangler config

Client

Start, monitor, and cancel workflow instances

Build docs developers (and LLMs) love