Topic 200 / Advanced
Resilience and chaos testing
Chapter 12.3 · Testing Strategies
What and why
Resilience patterns — circuit breaker (→ 151), retry with backoff (→ 152), bulkhead (→ 153), graceful degradation (→ 154) — are code written to handle failure, but code that handles failure is only proven once a real failure actually happens to it. Chaos testing deliberately injects failure (kill an instance, add latency, block a dependency) under controlled conditions, to find out whether those patterns engage the way the design assumed. Builds on: → 199 (load, stress, spike and soak testing).
Diagram
1. state a steady-state hypothesis ("error rate stays < 1% during this experiment")
2. inject a controlled fault (kill an instance / add latency / block a dependency)
3. observe the real system (→ 201, → 202 — metrics, traces, logs)
4. compare: did the hypothesis hold?
yes ──► resilience pattern engaged as designed
no ──► found a real gap; fix it, then re-run as a regression check
How it works
- Write a steady-state hypothesis in measurable terms before touching anything — "error rate stays under 1%," not "the system should be fine."
- Choose one controlled, bounded fault: kill one instance (does the load balancer, → 92, reroute?), inject latency into one dependency call (does a timeout and circuit breaker, → 151–152, engage?), or block a dependency entirely (does graceful degradation, → 154, kick in?).
- Run the experiment with a bounded blast radius — a known, limited scope, and a rollback ready — never as an unannounced surprise against unbounded production traffic.
- Observe the real, measured behavior through the same signals an incident would use (→ 201, → 202), not through assumption.
- Compare observed behavior to the hypothesis; a held hypothesis is evidence the pattern works under real failure, and a broken one is a genuine gap, found safely, worth fixing and then re-testing as a standing regression check.
Practical example
(illustrative). Three instances serve 300 requests/second behind a load balancer; hypothesis: "killing one instance keeps the error rate under 1% for the 5-second window around the kill." One instance is killed. If the load balancer's health check and rerouting work as designed, the measured error rate during that window is, say, 0.3% — hypothesis holds. If instead no circuit breaker protects calls to the now-missing instance and callers retry blindly against it until the health check catches up, the measured error rate spikes to 15% — the hypothesis fails, and the gap (no circuit breaker on that call path) is now a known, fixable finding instead of a surprise during a real incident.
When to use it
- Use once basic resilience patterns (→ 151–154) are believed to be in place and need verification under real, not imagined, failure.
- Avoid running chaos experiments with an unbounded blast radius or no rollback plan — the experiment itself must not be able to cause the outage it's meant to prevent.
- Failure scenarios: a chaos experiment that takes down a dependency shared by systems outside its intended scope, because the blast radius wasn't actually bounded; resilience code that looks correct in review but was never exercised, so its first real test is an actual incident instead of a planned one; a hypothesis stated too vaguely to say afterward whether it held.
- Simpler alternative: for an early-stage system, a tabletop exercise — walking through "what happens if X fails" on paper with the team, with no code run — finds some of the same gaps before any live fault injection is justified.
Practice
(tabletop plus a small lab exercise; 20–30 min; lab: stop a container, e.g. Redis, while a dependent script runs).
- Tabletop: for a system you know, write one steady-state hypothesis and predict what would happen if its database became unreachable for 30 seconds — name which resilience pattern (if any) should engage.
- Live, bounded version: run a small script that reads from Redis in a loop; stop the Redis container mid-run; observe and record the script's actual behavior (does it error loudly, retry, or hang?) against your tabletop prediction.
- State one concrete gap your live test revealed that the tabletop prediction missed, if any.
Done when the live test's observed behavior is recorded and explicitly compared, point by point, to the tabletop prediction.
Shared lab setupKey takeaway
Chaos testing proves resilience patterns engage under real, controlled failure instead of assuming they do — state a measurable hypothesis, inject one bounded fault, and compare. Done when you can: run one bounded chaos experiment, state whether the hypothesis held, and name the specific resilience pattern (or gap) the result points to. Used next in → 201 (observability, what a chaos experiment is read through), → 207 (production readiness, where rehearsed resilience is a launch gate).
References
Site Reliability Engineering, 2nd edition; The Site Reliability Workbook —
see references.md.