Skip to content

B.10 Pass 8: Durable Execution

Corpus builds and training runs take hours, and over hours something always fails: a process crashes, a deploy restarts a pod, a node is preempted. This pass builds the course’s own durable execution engine so that a failure costs a retry from the last recorded step rather than the whole run, and so that the history says exactly what happened. It starts with an append-only event log and a task queue with fenced leases, adds a workflow service, a worker SDK, activities with retries and heartbeats, deterministic replay, timers, signals, and sagas, and then runs the Pass 3 corpus pipeline and training as workflows.

Concepts from other sections (16)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

  • Durable execution: persisting the progress of a long-running computation step by step, so it can crash and resume where it left off without redoing completed work; Temporal, Cadence, and DBOS provide it. Read more: Chapter 7: Durable Orchestration and Workers in Systems Engineering
  • task queue: the durable server’s routing key; only pollers of queue agent receive AgentRun tasks. Read more: 10.8 The agent image and chart in Systems Engineering
  • Kill loop: a seeded loop that crashes the system at many points and checks every promise at the end. Read more: 3.7 Resilience tests in Software Engineering
  • StatefulSet: a workload controller that gives each Pod a stable name and its own persistent claim, with ordered rollout. Read more: 10.7 Durable and worker images and charts in Systems Engineering
  • Poison task: a task that fails the same way on every attempt, so retries cannot fix it. Read more: 12.4 A poison task lands in the dead-letter queue in Systems Engineering
  • Idempotency key: a key, the same on every attempt, by which the external system deduplicates an effect. Read more: 3.7 Resilience tests in Software Engineering
  • Visibility timeout: the lease length VV; a leased task is invisible to other pollers until it expires. Read more: 7.3 The task queue in Systems Engineering
  • Dead-letter queue (DLQ): where a task is parked after MM attempts, to be redriven by an operator. Read more: 7.3 The task queue in Systems Engineering
  • Worker pool: stateless processes that long-poll a durable queue, execute tasks, and report results; because all state lives in the queue or engine, workers can crash, deploy, and autoscale freely. Read more: Chapter 7: Durable Orchestration and Workers in Systems Engineering
  • Durable timer: a timer whose existence and deadline are recorded in history as TimerStarted{fire_at}, so it survives any restart. Read more: 7.7 Durable timers in Systems Engineering
  • Subprocess activity: one attempt at one activity, run as a child process of a Go worker, whose interface is files, environment variables, signals, and an exit code. Read more: 7.9.4 Failure tests and integration in Systems Engineering
  • write-ahead logging (WAL): a journal mode in which commits append pages to a log, so readers and the single writer do not block each other. Read more: 1.11 SQL and SQLite: schema, transactions, WAL mode, indexes, aggregates in Programming and Algorithms
  • PersistentVolumeClaim (PVC): a request for storage that outlives any one Pod. Read more: 10.4 Helm charts and the observability stack in Systems Engineering
  • KEDA: an operator that scales workloads on external metrics by creating and driving an HPA. Read more: 10.7 Durable and worker images and charts in Systems Engineering
  • Resilience test: a test that injects a fault at a chosen moment and checks a promise of the system afterwards. Read more: 3.7 Resilience tests in Software Engineering
  • Dead-letter queue: where a task goes after exhausting its budget; nothing retries it until a human redrives it. Read more: 12.4 A poison task lands in the dead-letter queue in Systems Engineering

The point of the pass is that failures do not change results. Every piece is tested under kill loops, and the end-to-end checks require that a corpus build or training run killed repeatedly produces exactly what an uninterrupted run produces. On kind, the durable server runs as a StatefulSet with KEDA-scaled workers and control-plane traces, and two drills (the server killed in a loop, and a poison task) are resolved.

Learning objectives

  • Explain how the event log, task queue, and leases make every effect land exactly once.
  • Explain how deterministic replay rebuilds a workflow’s state from its history.
  • Explain how retries, backoff, heartbeats, and idempotency keys make activities safe to repeat.
  • Explain how CorpusBuild and TrainRun reproduce their direct-run results under kills.

This pass needs Pass 7, whose kind deployment and observability stack the durable services join.

  1. The append-only event log. Afterwards you can explain how the append-only segmented event log writes, syncs, rolls over, and recovers.
  2. The task queue. Afterwards you can explain how the task queue uses visibility timeouts and fenced leases, retries to a DLQ, and long-polls.
  3. The workflow service. Afterwards you can explain how the workflow service makes start idempotent and serves describe, list, and paged history.
  4. The task protocol and workers. Afterwards you can explain the task gRPC protocol and how the Go worker SDK and worker pool poll and complete tasks.
  5. Activities. Afterwards you can explain how activities retry with backoff and jitter, time out, heartbeat, and use idempotency keys.
  6. Deterministic replay. Afterwards you can explain why workflows must be deterministic for replay and how ContinueAsNew, history paging, and payload limits keep history bounded.
  7. Durable timers. Afterwards you can explain how durable timers survive restarts and how the test clock drives them.
  8. Signals, cancellation, and sagas. Afterwards you can explain how signals and cancellation reach a workflow and how a saga compensates completed steps.
  9. Subprocess activities: the Go runner and the Python helper. Afterwards you can explain how the subprocess activity runner launches Python activities and how the helper reports results.
  10. CorpusBuild: the pipeline as a durable workflow. Afterwards you can explain how CorpusBuild runs the data pipeline as a durable workflow and resumes after a crash.
  11. Platform workflows: TrainRun and EvalSuite. Afterwards you can explain how the TrainRun and EvalSuite workflows orchestrate training and evaluation.
  12. Durable and worker images and charts. Afterwards you can explain why the durable server is a StatefulSet with a WAL PVC and how KEDA autoscales the workers.
  13. Observability for the control plane. Afterwards you can explain the workflow and activity spans and what the queue and DLQ panels show.
  14. Resilience tests. Afterwards you can explain how resilience tests inject crashes and partitions and what they assert.
  15. The durable server is SIGKILLed in a loop during a corpus build. Afterwards you can explain why a corpus build survives the durable server being SIGKILLed in a loop, and diagnose it when it does not.
  16. A poison task lands in the dead-letter queue. Afterwards you can explain how a poison task reaches the dead-letter queue and how it is diagnosed and redriven.
  17. What the System Does After Pass 8. Afterwards you can explain how CorpusBuild, TrainRun, and EvalSuite run to completion on the durable engine, locally and on kind, and survive crashes.

One optional section replicates the durable log with Raft:

  1. Raft high availability for the durable log (optional). Afterwards you can explain how Raft elects a leader and replicates the durable log so it survives leader loss.

The stages are also in this pass’s manifest, path.tsv. Pass 9 uses these workflows to train and release the course’s first model worth serving.

Generated from path.tsv.

StageReadDone when
1Append-only segmented event log
7.1 The append-only event log
You can explain how the append-only segmented event log writes, syncs, rolls over, and recovers (dur.01).
2Task queue: visibility timeout, fenced leases, retries to DLQ, long poll
7.3 The task queue
You can explain how the task queue uses visibility timeouts and fenced leases, retries to a DLQ, and long-polls (dur.03).
3Workflow service + idempotent start, describe, list, paged history
7.2 The workflow service
You can explain how the workflow service makes start idempotent and serves describe, list, and paged history (dur.02).
4Task gRPC protocol, Go worker SDK, worker pool
7.4 The task protocol and workers
You can explain the task gRPC protocol and how the Go worker SDK and worker pool poll and complete tasks (dur.04).
5Activities: retries, backoff + jitter, timeouts, heartbeats, idempotency keys
7.5 Activities
You can explain how activities retry with backoff and jitter, time out, heartbeat, and use idempotency keys (dur.05).
6Deterministic replay workflows, ContinueAsNew, history paging, payload limits
7.6 Deterministic replay
You can explain why workflows must be deterministic for replay and how ContinueAsNew, history paging, and payload limits keep history bounded (dur.06).
7Durable timers and the test clock
7.7 Durable timers
You can explain how durable timers survive restarts and how the test clock drives them (dur.07).
8Signals, cancellation, sagas (compensation)
7.8 Signals, cancellation, and sagas
You can explain how signals and cancellation reach a workflow and how a saga compensates completed steps (dur.08).
9Subprocess activity runner (Go) and the Python activity helper
7.9 Subprocess activities: the Go runner and the Python helper
You can explain how the subprocess activity runner launches Python activities and how the helper reports results (dur.09).
10Pipeline as a durable workflow CorpusBuild
5.9 CorpusBuild: the pipeline as a durable workflow
You can explain how CorpusBuild runs the data pipeline as a durable workflow and resumes after a crash (data.09).
11Platform workflows TrainRun and EvalSuite
7.11 Platform workflows: TrainRun and EvalSuite
You can explain how the TrainRun and EvalSuite workflows orchestrate training and evaluation (dur.11).
12Durable and worker images and charts: WAL PVC, StatefulSet, KEDA autoscaling of workers
10.7 Durable and worker images and charts
You can explain why the durable server is a StatefulSet with a WAL PVC and how KEDA autoscales the workers (dep.06).
13Observability for the control plane: workflow and activity spans, queue and DLQ panels
11.6 Observability for the control plane
You can explain the workflow and activity spans and what the queue and DLQ panels show (obs.05).
14Resilience tests (R10)
3.7 Resilience tests
You can explain how resilience tests inject crashes and partitions and what they assert (craft.21).
15The durable server is SIGKILLed in a loop during a corpus build
12.3 The durable server is SIGKILLed in a loop during a corpus build
You can explain why a corpus build survives the durable server being SIGKILLed in a loop, and diagnose it when it does not (ops.02).
16A poison task lands in the dead-letter queue
12.4 A poison task lands in the dead-letter queue
You can explain how a poison task reaches the dead-letter queue and how it is diagnosed and redriven (ops.03).
17What the system does after Pass 8
B.10.1 What the System Does After Pass 8
You can explain how CorpusBuild, TrainRun, and EvalSuite run to completion on the durable engine, locally and on kind, and survive crashes.
18Raft HA for the durable log (optional)
7.10 Raft high availability for the durable log (optional)
You can explain how Raft elects a leader and replicates the durable log so it survives leader loss (dur.10).