Sub topic 15
Testing Failover: Drills, Game Days, and Fault Injection
This chapter assumes you know how health checks, failover sequences, replication, RTO and RPO, split brain, and failback work. Here you learn how to prove that a design works before a real outage tests it for you.
Why untested failover fails
A failover path that has never run is a hypothesis. Common reasons it breaks:
- The standby has drifted from the primary: different config, older software, or missing secrets.
- Health check thresholds were never tuned against real failure behavior.
- The standby cannot handle full production load.
- Runbooks are out of date, or only one person knows the steps.
- Replication lag is larger than the RPO you promised.
Testing turns these from surprises during an outage into tickets in a backlog.
Three kinds of tests
| Test | What happens | Risk | Best for |
|---|---|---|---|
| Drill | A planned, scripted failover, often in staging or in a maintenance window | Low | Checking runbooks and basic mechanics |
| Game day | A team exercise where a failure is introduced and people respond as in a real incident | Medium | Checking people, alerts, and communication |
| Fault injection | Automated, repeated failures created by tooling | Varies | Checking behavior continuously as the system changes |
Start with drills. Move to game days once drills pass. Add automated fault injection once the team trusts the system enough to run it often.
Designing a test
Write each test as an experiment with these parts:
- Steady state. The metric that shows the system is healthy, such as the success rate of requests.
- Hypothesis. A specific claim, such as "If the primary database host stops, writes resume within 60 seconds and no committed write is lost."
- Failure to inject. One change, such as killing a process or blocking a network path.
- Measurements. Time to detect, time to switch, time to full recovery, and data lost.
- Abort condition. A threshold that stops the test, such as an error rate above 5% for two minutes.
Compare the measured times with your RTO and RPO. A test that meets the objective only once is weak evidence. Repeat it.
What to inject
Choose failures that match the failure modes in your design:
- Stop a process or host to test crash failover.
- Block network traffic between nodes to test partitions, split brain, and fencing.
- Add latency or packet loss to test whether health checks produce false positives.
- Fill a disk or exhaust memory to test partial failures that leave a node up but useless.
- Take down a whole fault domain, such as a zone, to test capacity in the survivors.
- Stop the standby, to confirm that you are alerted when redundancy is lost.
Partial failures reveal the most. A host that is slow but still answers health checks often causes worse outages than one that is cleanly dead.
A small fault injection script
This script stops the primary container, then measures how long a service takes to answer again. It assumes Docker is installed, a container named primary exists, and the service listens on localhost:8080.
import subprocess
import time
import urllib.request
URL = "http://localhost:8080/health"
def healthy():
try:
with urllib.request.urlopen(URL, timeout=1.0) as resp:
return resp.status == 200
except OSError:
return False
assert healthy(), "system is not in steady state"
subprocess.run(["docker", "stop", "primary"], check=True)
start = time.monotonic()
while not healthy():
if time.monotonic() - start > 120:
raise SystemExit("abort: no recovery within 120 seconds")
time.sleep(0.5)
print(f"recovered in {time.monotonic() - start:.1f} seconds")The script checks the steady state first, injects one failure, and enforces an abort condition. Compare the printed time with your RTO.
Include failback
Test the return path too. After a failover, bring the old primary back and check that it rejoins as a standby, resynchronizes its data, and does not take over by accident. Many split brain incidents happen during recovery, not during the failure.
Common mistakes
- Testing only clean crashes and never partial failures.
- Testing at low load, then failing under peak traffic.
- Measuring recovery by whether a process started, not whether users can complete requests.
- Fixing findings informally. Track each one with an owner and a retest date.
Exercise
Your RTO is 60 seconds. A drill shows the standby is promoted in 20 seconds, but clients see errors for 3 minutes. Name two likely causes and one measurement that would confirm each.
Show answer
Likely causes include DNS caching, where clients keep resolving the old address until the TTL expires (measure which IP clients resolve over time), and clients holding open connections to the dead primary with long timeouts or no endpoint list (measure client timeout settings and connection errors). Another cause is a load balancer health check that is slow to mark the new primary healthy (measure when the balancer first sends it traffic). The drill showed that promotion time is not the same as recovery time for users.