How it works

The model drawn: a run from intent to facts, a step and its undo, the ledger's chain, the lifecycle, the dispatcher, where it all runs, and what is stored against what is derived.

Open in CursorView as Markdown

This page draws the model that Concepts names and Design paradigms defends: seven pictures, each with the words the engine uses for its parts. The commands it points at are durable-sdk explain <runId>, durable-sdk limits, durable-sdk ledger export --out <file>, durable-sdk ledger verify --file <export> and durable-sdk doctor --host.

A run, end to end#

A run from its intent to its facts trigger 1 trigger 2, the same key intent key = f(input) execute: one run per key step 1: read step 2: write step 3: external facts no row row 1: step 2 row 2: step 3 listeners input + requestId never the clock a second trigger joins the first irreversible: read an undo, a row under a writeKey the final status a read before, after, hash before, after, hash each its own run the ledger: hash-chained, append-only outbox
A trigger becomes a key, the key one run, the run its steps in order, each write a row on the ledger chained to the row before it, and the facts at the end each listener's own run.

A trigger (a route, a webhook, a schedule, a button) calls execute(input, { actor }). The key is a pure function of the input, key: ["checkoutId", "requestId"], and never reads the clock: the moment rides in the input as requestId. The run and its key commit in one transaction, so a second trigger of the same key, from another caller or a retried request, joins the run in flight and gets its result. It never starts a second one.

The body runs its steps in order. A read step leaves its row and no image. A write reads before it writes, writes once, and leaves a before and an after image on the ledger under the run, the step, the actor and the attempt. A write a provider cannot repeat runs as an external step under a writeKey, the intent recorded before the call, so a redrive after a lost answer finds what landed instead of writing again. Each step's input and output land on a row before the body goes on; after a crash the next attempt replays the finished rows and re-invokes only what did not finish.

At the end the run emits its facts through ctx.emit(). A fact is a row of the catalog with a typed payload and a clock-free key, written in the same transaction as the run's final status and inserted-if-absent under its key, so a fact of an attempt that threw is dropped and a resend collapses. The outbox delivers it to each listener, and a listener is itself a keyed run, listener.<name>:<outboxId>, so a redelivery is harmless. Events and listeners has the forms.

A step and its undo#

Three steps forward, two undos back in reverse order step 1 step 2 step 3: throws undo step 2 undo step 1 limbo row 4: undo 1 row 3: undo 2 completed, row 1 completed, row 2 nothing of it to undo before image, restored before image, restored a person decides compensation, in reverse found, restored found, restored the ledger: each undo its own row all undone: COMPENSATED FAILED: redrive, dismiss or undo the world moved: stop
When step 3 throws, the saga undoes step 2 and then step 1, each undo its own row on the chain; an undo that finds the world moved stops, and the run waits in limbo for a person.

Every step that changes the world carries an undo with its effect (provider, ledgered or external) or says irreversible: "<why>"; the door refuses one that says neither. When step 3 throws, the saga runs the finished steps' undos in the reverse of their completion order: step 2's, then step 1's. Each undo gets the step's stored output and writes its own <step>.undo row with the image it found and the image it restored. When every compensable step is undone the run lands COMPENSATED; a step that said irreversible is left standing, listed on the run's compensation, and the error names it.

An undo is a compare-and-set on the before image, never an overwrite. One that finds the world moved under it (a later actor changed the row) fails by name and stops: nothing is written over what the later actor did, the run lands FAILED with the step named, and it waits in limbo for a person. Nothing is retried in the dark. Steps and undo has the three forms and the external step.

The ledger's chain#

Two scopes, each a chain of hashed rows from genesis the operator API's verify read: each chain from genesis, every link recomputed scope A scope B genesis row 1 row 2 row 3 genesis row 1 row 2 row 3 hash h0 prev h0, hash h1 prev h1, hash h2 prev h2, hash h3 hash g0 prev g0, hash g1 prev g1, hash g2 prev g1, hash g3 append-only three times: the interface, retention, a database trigger the first link that does not hold, named
Each scope is its own chain: every row hashes the row before it, and verify recomputes the chain from genesis and names the first link that does not hold.

Every write a step makes leaves a row with the image it found and the image it left. Rows chain per scope (a tenant, a store, a till): each carries prevHash, the hash of the row before it, and hash = sha256(prevHash + content), from a genesis row per scope. The append takes the scope's lock, so one scope's writers queue and scopes append side by side.

The ledger is append-only three times over: the store's interface has no update and no delete for it, the retention rules never prune it, and a database trigger (ledger_append_only, BEFORE UPDATE OR DELETE on every row, with a truncate twin on every partition) refuses the statement. The operator API's verify read recomputes every chain from genesis and names the first broken link; durable-sdk ledger export --out <file> writes the rows out and durable-sdk ledger verify --file <export> walks the export offline. Nothing personal belongs in an image: the redaction policy blanks a secret by name and by shape before a row is written (Data in the ledger).

The lifecycle#

The states of a run and what moves it between them execute() RUNNING COMPLETED WAITING compensation limbo UNDONE one run per key attempt n the facts delivered the body returns a wait a wake no function held undos in reverse FAILED or COMPENSATED the key released a person's undo dismiss: it stays, with a reason a step throws, or a cancel redrive: a person, attempt n+1
A run is RUNNING or WAITING until its body returns or a step throws; a failure compensates into limbo, where a person redrives, dismisses or undoes it.

execute claims the run with a lease and runs it RUNNING. A wait (a timer, a fact, a signal, a child, a slot) parks it WAITING and holds no function; the dispatcher wakes it as the next attempt. The body's return lands it COMPLETED, its facts in the same commit. A step that throws, a cancel a person pressed (ended at the next step boundary as Cancelled) or a run past its timeout sends it into compensation, and it lands COMPENSATED when every undo held, FAILED when one could not or a step was irreversible.

FAILED and COMPENSATED are limbo. A run there is never retried by code: a person redrives it (attempt n+1 under the same run id, replaying the rows that landed), dismisses it with a reason, or undoes it, which lands UNDONE and releases the key. The one exception is a transient cause the engine recognises, redriven once by itself. A run that outgrows its history closes CONTINUED under the same key (Changing a workflow). durable-sdk explain <runId> --api <url> prints a run's sentence and its remedy.

The dispatcher#

The minute tick, its lanes and partitions, the claims, and the wakes between ticks the minute tick lanes partitions claim: a lease a wake between ticks runs resumed the sweeper, every tick cron: GET /jobs/dispatch side by side each in order fenced by attempt a timer due, a fact landed, a signal listeners run kicks the drain inline an expired lease resumed, a lost kick delivered, a due timer fired
Once a minute the tick runs its lanes over the partitions and claims what is due; a wake between ticks does the same work early, and the sweeper catches whatever a wake lost.

The engine has one moving part outside your app: a cron that requests GET /jobs/dispatch once a minute behind a bearer. The tick runs its lanes side by side; each lane takes partitions, and a partition's facts reach their listeners in order. A lane claims a run or a row with a lease, fenced by (runId, attempt), so two ticks never act on one run; the claimed run resumes, the claimed fact runs its listener.

Between ticks a wake does the same work early: a write that lands a fact kicks the dispatcher inline in the same invocation, a timer fires at its moment, a signal when a person presses it. Nothing depends on the kick arriving. The sweeper is the tick's own second pass: it resumes any run whose lease expired, delivers any row a kick lost and fires any timer that is due, so the worst case for a lost wake is a minute. Retention runs on its own schedule (retention.apply), prunes finished runs, their steps and delivered rows past their windows, and never touches the ledger. On the hosted platform a preview has no cron and ticks on a request (The platform).

Where it runs#

Your app's process beside your Postgres, the cron the one thing outside your app's process your Postgres routes and webhooks workflows and listeners the engine, a library the adapter: deadline, wake your tables the engine's tables the cron: GET /jobs/dispatch schema durable: runs, steps, keys, waits, the outbox, the ledger made by durable-sdk migrate no cluster, no broker, no worker every minute, the one thing outside hosted: the same tree, a project and a database
The engine is a library in your own process and a schema in your own database; the cron is the one thing outside, and the hosted platform runs the same tree.

Durable is a library. Your routes, your workflows and the engine run in one process: a serverless function, or a long-lived one. The engine's tables sit in a schema of their own, durable, in the database your app already has, made by durable-sdk migrate and never modelled by your ORM; a fact and your own row share one commit. No worker, no broker, no control plane: the request path is your function and your Postgres, and the cron is the one thing outside.

The platform is a seam, Platform, with one adapter per platform: the function's deadline, so a run parks before the kill; the wake and the keep-alive; the identity. A platform with no wake runs on the cron tick alone. Hosted, the tree runs on a project with a database beside it and the cron set for you. On a two-vCPU CI runner with Postgres over loopback, a ten-step run of read steps is 12 statements with completion: "behind" (22 under the default) and 12 rows, about 4,000 runs a minute at eight starters in one process on a ten-connection pool (develop's bench run 40945075490, 2026-10-29); Why Durable has the numbers beside the alternatives.

What is stored, what is derived#

The one record on the left, five kinds of row and the catalogues, and on the right what is derived from it when read the one record, stored once derived when read, never stored a second time runs steps the ledger facts the outbox the catalogues the result, the resume point the console's views issues and limbo the limits verify's verdict llms.txt, openapi.json workflows, facts, routes, pages off the row; the finished steps replayed overview, pressure, caps, downstream runs the failed runs, grouped by cause the attempts, the windows, the bounds every chain recomputed from genesis from the pages and the route table a copy your app keeps: stamped with its moment, rebuilt from its source, never written back
The rows are written once and read many ways: a run's result and its resume point, the console's views, limbo, the limits, the verify verdict and the agent's files are derived from them and the catalogues, and nothing is stored twice.

The engine keeps one record: the run rows, the step rows, the ledger, the fact rows and the outbox, in the durable schema. Everything the console shows is a read over them and the catalogues (the registered workflows, the facts, the route table), computed when it is asked for and never stored a second time: a run's result as execute answers it for a run already landed and as durable-sdk explain <runId> --api <url> says it, its resume point on a redrive (the finished step rows replayed, the rest re-invoked), the overview, the pressure view, the caps, the issues (limbo grouped by cause), the limits in force (durable-sdk limits --api <url>), the facts a run emitted and the runs they started. The operator API's verify read recomputes every chain from its rows, and durable-sdk ledger verify --file <export> walks an export to the same verdict with no database at all. The agent's surfaces are derived the same way: /llms.txt and the .md twins from the docs' pages, /openapi.json from the route table.

The world is never mirrored into a table the workflow trusts over it. A step reads it (a provider's answer, a store's stock) and the answer is the step's row; a write leaves the image it found and the image it left on the ledger; a decision is made on what a step read, never on a copy. Where the engine keeps a derived copy of its own (the console's day summaries, the last full walk of the ledger) the row is stamped computedAt, served stale and recomputed after the response, and a broken ledger is never served from a copy. Design paradigms states this as the eleventh rule, with the failure it removes; The till tells it as a cash register, the tape against the stored number.

Where to go next#