Chapter 12: Incident Response and Recovery
Every system fails; what differs is how long it stays failed. Time to mitigate is mostly time spent working out what is wrong, so the work that pays is making the next diagnosis shorter: telemetry that shows the cause, runbooks that say where to look, and rollouts that can be undone in one command. This chapter teaches that work the way it is best learned, by causing incidents on purpose. Each section is a drill: it injects a known fault into the running system you built across these books, and walks through how the fault is detected, mitigated, and recorded.
Concepts from other sections (20)
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.
- SIGKILL: an uncatchable signal that ends a process between two instructions, leaving only what is on disk. Read more: 12.3 The durable server is SIGKILLed in a loop during a corpus build
- OOMKilled: the termination reason for a container killed for exceeding its memory limit (exit code 137); it is a kill, not a slowdown. Read more: Chapter 10: Kubernetes Workloads and Deployment
- CrashLoopBackOff: the pod status while the kubelet waits, with doubling delay capped at 5 minutes, before restarting a container that keeps exiting. Read more: 12.1 First drill: the engine crashloops
- readiness probe / liveness probe: checks that, on failure, remove a Pod from its Service or restart its container, respectively. Read more: 10.1 Tracer deploy: images, a kind cluster, two Helm charts, and Jaeger
- Runaway agent: an agent run that keeps calling the model or tools without converging, spending budget without useful work. Read more: 12.11 A runaway agent
- Blameless postmortem: the fixed-shape record of one incident that names system properties, not people. Read more: 12.1 First drill: the engine crashloops
- Chaos engineering: deliberately injecting failures (killing a pod, adding latency, partitioning the network) to test the hypothesis that a system tolerates them; it starts with a small blast radius and a defined steady-state metric, and needs good observability to be safe. Read more: Chapter 3: The Testing Mentality in Software Engineering
- Service Level Objective (SLO): a target for a defined measure of service behavior over a specified window. Read more: Chapter 13: Engineering Acronyms in Software Engineering
- Time-to-first-token (TTFT): the delay between sending a request and receiving the first generated token. Read more: Chapter 4: Streaming and SSE
- Commit rule: before the first byte, retry elsewhere; after it, end the stream with an SSE
errorevent. Read more: 12.2 A decode worker dies mid-stream - Capacity during replacement: the headroom the remaining replicas have while a lost one is rescheduled and warmed up. Read more: 12.2 A decode worker dies mid-stream
- Contract suite: tests that exercise behaviour at an interface (OpenAPI conformance, ABI and format tests). Read more: 12.7 A breaking dependency upgrade
- Last known good image: the tagged artifact that already ran in production, kept so rollback is a redeploy. Read more: 12.7 A breaking dependency upgrade
- First bad commit: the earliest revision on which the regression reproduces, confirmed against its parent. Read more: 12.8 A performance regression bisect
- Verified snapshot: the last corpus state that passed
ledger verify, used as the base for a rebuild. Read more: 12.9 A data incident - agent loop: repeated model calls, each followed by running the tool calls it returned and appending their results, until a reply has no calls. Read more: 28.3 The agent loop in AI Engineering
- Propagated cancellation: cancellation that ends in-flight LLM requests and tool subprocesses, not just the loop. Read more: 12.11 A runaway agent
- Terminal reason: the final status that names which budget stopped the run. Read more: 12.11 A runaway agent
- WAL quota:
[durable].wal_max_bytes(default 2 GiB,walMaxBytesin the chart), the cap above which appends are rejected. Read more: 12.12 The event log disk fills up - Membership change: adding or removing replicas, which must not happen while the cluster is partitioned. Read more: 12.13 A Raft partition (optional)
Three habits run through every drill. The first is triage on Kubernetes, from the outside in: which workload is unhealthy, why its last container exited (exit code and reason), what its previous log says, and what changed (rollout history). Exit codes below 128 mean the program chose to exit; 128 + n means signal n (137 is SIGKILL, usually OOMKilled; 143 is SIGTERM). A CrashLoopBackOff waits 10 s between restarts, doubling to 5 minutes. The second habit is mitigation before root cause: roll back the change that started it (kubectl rollout undo, helm rollback), then fix forward through the chart, remembering that readiness probes and the rollout strategy decide whether a bad rollout becomes an outage. The third is learning from the incident. A runbook is written before the incident, for the person who did not build the system; a postmortem is written after, without blame, in fixed sections (Summary, Impact, Timeline, Root cause, Detection, Resolution, Action items), with action items that prevent, detect, or mitigate the next occurrence, each with an owner.
The arc of the chapter follows the system’s growth. The first drill has no alerting at all, so a person notices the crashloop. From the second drill on, burn-rate alerts do the noticing, and time to detect and time to mitigate can be measured from Prometheus. The first four sections are full worked incidents, each with a timeline worked by hand, a model runbook, and a model postmortem. The remaining nine are shorter drills built around the runbook a correct response requires: planned migrations and upgrades that can go wrong, regressions, bad data, noisy tenants, runaway agents, a full disk, and, optionally, a Raft partition. These practices come from the industry: Google’s SRE incident command and blameless postmortems, Netflix’s chaos engineering against production, and the habit, common to any good on-call team, of linking a runbook from every alert and running game days.
Learning objectives
- Triage a failing Kubernetes workload from the outside in, reading exit codes, previous logs, and rollout history.
- Mitigate before finding the root cause, and choose between waiting, scaling, rolling back, and fixing forward.
- Compute when a burn-rate alert fires for a given fault, and measure time to detect and time to mitigate.
- Verify recovery by the SLO and by the system’s output, not by pod status.
- Write runbooks for symptoms and blameless postmortems whose root causes name system properties.
Before you begin
Section titled “Before you begin”The drills act on the Kubernetes objects of Cloud Native and are detected by the SLOs, burn-rate alerts, and dashboards of Observability, so read both chapters first. Runbooks and decision records are covered in depth in the documentation writing chapter of Software Engineering. Each drill names the local deployment sections and the companion AI Engineering sections that built the component it breaks. Before you read a drill’s solution, predict the diagnosis commands and their output, then compare.
In this chapter
Section titled “In this chapter”- First drill: the engine crashloops. A bad rollout points the engine at a missing model directory. With no alerting, you triage the crashloop by hand, roll back, and write your first runbook and postmortem.
- A decode worker dies mid-stream. One of two decode pods is deleted under load. The TTFT budget burns, the gateway’s commit rule keeps streams honest, and the root cause is capacity during replacement.
- The durable server is SIGKILLed in a loop during a corpus build. Five kills cost time but not correctness: leases redeliver, idempotent activities make the second delivery harmless, and the output must equal a clean run’s.
- A poison task lands in the dead-letter queue. A test-only failpoint reaches production and one task fails every attempt. You find what failed and what changed, fix, then redrive.
- The KV format v2 migration. A planned format change where readers must upgrade before writers, with block-hash evidence and a one-flag rollback.
- The API v2 migration. v1 and v2 served side by side, selected per request by a header, with every signal split by version.
- A breaking dependency upgrade. One dependency at a time, gated on contract suites and a like-for-like load comparison against the last known good image.
- A performance regression bisect. Control the measurement, fix the threshold in advance, and let
git bisect runfind the first bad commit. - A data incident. Bad data leaves every service green; quarantine, trace forward through the ledger, and rebuild from a verified snapshot.
- A noisy neighbor. One tenant’s flood raises everyone’s TTFT; attribute it per tenant and contain only the offender.
- A runaway agent. An agent loop bounded on every axis, with propagated cancellation and a terminal reason that names the budget.
- The event log disk fills up. A WAL quota turns a full disk into a clean
RESOURCE_EXHAUSTEDthat never loses acknowledged work. - A Raft partition (optional). For the three-replica durable log: minority writes fail, the majority elects a new leader, and you heal before any membership change.
Key terms
Section titled “Key terms”- Outside-in triage: diagnosing a failing Kubernetes workload from the outside in: which workload is unhealthy, why its last container exited, what its previous log says, and what changed in its rollout history.
- Signal exit code: a process exit code of 128 + n, meaning the process was killed by signal n (137 is SIGKILL, often OOMKilled; 143 is SIGTERM); codes below 128 are the program’s own choice.
- Mitigation before root cause: restoring service first, usually by rolling back the change that started the incident, and finding the cause afterwards, because diagnosis under pressure is slow.
- Fix forward: correcting an incident by shipping a new change rather than reverting, done after mitigation and through the normal release path.
- Game day: a scheduled exercise that injects a known fault into a running system so the team practises detection, mitigation, and runbooks before a real incident.
Further reading
Section titled “Further reading”- Site Reliability Engineering (Google, free): ch. 12 Effective Troubleshooting, ch. 14 Managing Incidents, ch. 15 Postmortem Culture. Read one chapter after each drill and compare its advice with the model response.
- The Site Reliability Workbook (free): ch. 9 Incident Response and ch. 10 Postmortem Culture.
- Rosenthal and Jones, Chaos Engineering (O’Reilly).
- Kubernetes docs, Debug Applications (free).