Durable execution: workflows that outlive the process
Lesson 6.05 gave you the saga: a business process spread across services, each step with a compensating action, no distributed rollback. It described the pattern honestly and then quietly left you with the hard part. A saga has state — which step are we on, what did step two return, when does the reservation expire — and something has to hold that state across minutes, days, and the process restart that happens in the middle.
Write out what a five-step order flow actually needs and the list is uncomfortable. It must survive the pod being rescheduled between step three and step four. It must not run step three twice when it resumes. It must wait two days for a supplier callback without holding a thread. It must retry step four eleven times with backoff, and after the twelfth, run compensations for steps one to three in reverse. It must be inspectable at 3am: where is order 88421 stuck, and why?
Teams build this. They build it every time, out of a workflow_state table, a cron job that sweeps stuck rows, a status enum that grows a value per release, and a pile of if statements reconstructing where they were. It works, it is nobody's favourite code, and it is reinvented once per company. The category of infrastructure that does it for you is called durable execution, and it is what teams actually build sagas on now: Temporal, AWS Step Functions, Azure Durable Functions, Cadence, and a growing set of library-shaped versions that run against your own database.
The idea: the call stack becomes persistent
You write the workflow as ordinary sequential code — call this, await that, sleep for two days, then call the other thing. The engine records every step's result in durable storage as it happens. When the process dies, another worker picks the workflow up and reconstructs its position by replaying the recorded history: every call that already completed returns its stored result immediately, instead of executing again, until execution reaches the first thing that never finished. Then it carries on.
Two categories of code, and the distinction is the whole model:
- The workflow — the orchestration itself. Replayed from history, so it must be deterministic: same history in, same decisions out. That rules out reading the clock, generating a random number or a UUID, iterating a hash map with unstable order, or calling a service directly. The engine gives you deterministic substitutes for the ones you legitimately need.
- Activities — the side effects. Charging a card, sending an email, calling an API. These are not replayed; their results are recorded and handed back. Each one gets its own timeout and retry policy, and each one must be idempotent, because at-least-once execution applies here exactly as Lesson 6.07 described it. Durable execution removes the bookkeeping, not the requirement.
What you get for accepting that constraint is disproportionate. await sleep(48h) becomes a timer in a database rather than a thread — a million workflows waiting two days cost you a million rows, not a million threads. Retries with backoff and a policy per step come free. A human approval step is just a wait for a signal. And because the history is the state, "where is order 88421" is a query with a full timeline, which is the operational property that makes the difference at 3am.
What it costs, honestly
The determinism rule is a real constraint on code that does not look constrained: an innocent Date.now() or a library that quietly caches something breaks replay, and it breaks it during a deploy rather than in a test. Worse, changing workflow code changes replay — in-flight workflows started against the old version will replay against the new one and diverge, so long-running workflows need explicit versioning, and a two-week workflow means two-week-old code paths you may not delete. You are also adding a stateful cluster to operate, or a vendor dependency at the centre of your order flow, which is exactly the kind of lock-in Lesson 14.06 asks you to price before signing.
Choosing, rather than adopting
The default answer for one background job is not a workflow engine. Walk the ladder:
- One step, retryable, no state? A queue and an idempotent consumer. Done.
- A few steps, all inside one service, all fast? A state column and a transactional outbox (6.05) is genuinely sufficient, and much less machinery.
- Long waits, compensations, human steps, or "which of the eleven steps are we on" is a question people ask? That is the shape durable execution exists for, and the moment to stop hand-rolling it.
Note what the third case really is: you were going to build a workflow engine anyway. The choice is not whether to have one, it is whether it is the one you maintain.
Believing durable execution makes the process exactly-once. It does not, and it cannot — Lesson 6.07 is not repealed by better infrastructure. The engine guarantees the workflow advances exactly once through its recorded history; the activity that charged a card may still have succeeded at the provider a moment before the acknowledgement was lost, and it will be retried. Every activity that touches money, an external system, or anything a customer sees still needs its own idempotency key. What you have bought is that you no longer have to write the resume logic, not that the distributed systems problem went away.
The tradeoff sheet
- Problem solved
- Long-running multi-step work that must survive process death without the team hand-rolling state machines, timers and resume logic for every workflow.
- Rejected, and why
- A queue plus explicit state in your own database does the same job with tools you already run. A cron job over a status column is cruder and entirely sufficient for small volumes.
- The trade
- A new stateful system on the critical path, a programming model with real constraints on what activity code may do, and determinism requirements that make ordinary refactors dangerous.
- First to break at 10x
- History size and worker capacity. Long-lived workflows accumulate event history, and at 10x the replay cost on recovery becomes the constraint.
- What it does to the bill
- Either a managed service priced per action or a cluster with its own datastore to operate. Neither is free, and both are justified by engineer time rather than compute.
- Day-2 operations
- Versioning is the hard part: workflows in flight were started by the old code. Have a deployment story for that before the second release, not after.