Sub topic 15
Testing failover: drills, game days, and fault injection
This chapter assumes you know how failover works: health checks, replication, RTO and RPO, quorum, fencing, and failback. It covers how to prove that your design works before a real outage does it for you.
Why untested failover is unreliable
A failover path runs rarely, so it rots. Configuration drifts, certificates expire, a password in the standby changes, and a firewall rule never gets copied. The first time anyone learns about the problem is during the outage.
Redundancy only adds availability if the switch works. Testing turns the numbers from your design, such as "RTO of 60 seconds" and "RPO of 5 seconds", into measured facts.
Common reasons failover fails in practice:
- The standby lacks capacity for the full load.
- Health check settings are too slow or too sensitive.
- Replication lag is larger than the stated RPO.
- Clients cache DNS answers longer than the TTL suggests.
- The old primary is not fenced and accepts writes after promotion.
- Runbooks are out of date or depend on one person.
Three kinds of tests
| Kind | What happens | Risk | Best for |
|---|---|---|---|
| Drill | A planned, scripted switch of one component, often in staging | Low | Checking the procedure and the runbook |
| Game day | A team exercise where a failure is introduced in a realistic environment and people respond | Medium | Testing detection, people, and communication |
| Fault injection | Automated, repeated injection of specific faults, often continuously | Varies | Finding regressions and edge cases |
Start with drills, move to game days, and automate with fault injection once you trust your safety controls.
Write a hypothesis first
Every test needs a statement that can be proven wrong. For example:
- "If the primary database host is terminated, the application resumes writes within 60 seconds, and no committed transaction is lost."
- "If one zone loses network connectivity, error rate stays under 1% for the whole event."
A good hypothesis names the fault, the expected behavior, and a number. The numbers should come from your RTO, RPO, and service level objectives.
Choose what to measure
Decide on metrics before the test starts.
- Time to detect: from the fault to the first alert or health check failure.
- Time to switch: from detection to traffic reaching the new component.
- Time to recover: total time until the service meets its objective. Compare this with the RTO.
- Data lost: committed writes missing after failover. Compare this with the RPO.
- User impact: error rate and latency seen by clients.
- Manual steps: how many human actions were needed, and how long each took.
Common faults to inject
Test more than "the server disappears". Real failures are messier.
| Fault | What it reveals |
|---|---|
| Stop a process | Whether the supervisor and health checks notice |
| Terminate a host | Whether replacement and failover work |
| Block network traffic between nodes | Partition behavior, quorum, and split brain |
| Add latency or packet loss | Whether slow is treated as down, and timeout settings |
| Fill a disk | Partial failure that health checks may miss |
| Pause a process (SIGSTOP) | Zombie primaries that wake up later, which tests fencing |
| Expire a certificate or credential | Hidden dependencies |
| Lose a dependency such as DNS or a cache | Cascading failures |
| Fail a whole zone | Capacity in the surviving zones |
The pause test is especially valuable. A process that freezes for 30 seconds, then resumes, behaves exactly like a former primary after a long garbage collection pause. If your fencing is correct, its late writes are rejected.
A small fault injection harness
The following script simulates the client-side behavior from the earlier endpoint-list example and measures how long a client sees errors while the primary is down. It uses only the standard library and runs as shown.
import time
class Endpoint:
def __init__(self, name):
self.name = name
self.up = True
def call(self):
if not self.up:
raise ConnectionError(self.name + " is down")
return self.name
def fetch(endpoints):
for endpoint in endpoints:
try:
return endpoint.call()
except ConnectionError:
continue
raise RuntimeError("all endpoints failed")
primary = Endpoint("primary")
secondary = Endpoint("secondary")
endpoints = [primary, secondary]
# Steady state: check the hypothesis baseline first.
assert fetch(endpoints) == "primary"
# Inject the fault.
primary.up = False
start = time.monotonic()
served_by = fetch(endpoints)
elapsed = time.monotonic() - start
print("served by:", served_by)
print("seconds until a successful response:", round(elapsed, 4))
assert served_by == "secondary", "hypothesis failed: no failover"
# Remove the fault and confirm recovery.
primary.up = True
assert fetch(endpoints) == "primary"
print("hypothesis held")The structure matters more than the code. It checks a baseline, injects one fault, measures, asserts the hypothesis, removes the fault, and confirms recovery. Every fault injection experiment should follow this order.
Running an experiment safely
Safety rules to apply:
- Verify the system is healthy first. Never inject a fault into a system that is already degraded.
- Limit the blast radius. Start with one instance, one zone, or a small share of traffic.
- Define abort conditions in advance, such as "error rate above 5% for 2 minutes".
- Keep a tested way to undo the fault quickly.
- Tell everyone who could be affected, including on-call staff and support.
- Schedule tests when people are available to respond, not on a Friday evening.
Running a game day
A game day is a structured session, usually two to four hours, with defined roles.
- Facilitator: runs the schedule and calls aborts.
- Fault injector: introduces the failure.
- Responders: the on-call team, who handle it as a real incident.
- Observers: record timings, decisions, and confusion.
A useful agenda:
- Briefing: scope, hypothesis, abort conditions, and communication channel.
- Baseline: confirm dashboards show a healthy system.
- Injection: start the failure, with or without warning to responders.
- Response: responders detect, diagnose, and recover using only the runbooks and tools they would have in a real outage.
- Restore: end the experiment and return to steady state.
- Review: a blameless discussion of what happened.
Unannounced scenarios test detection and alerting. Announced scenarios test the recovery steps. Use announced scenarios first.
Test failback and data too
Teams often test the switch to the standby and stop. Also test:
- Failback: returning to the original primary, including resynchronizing data after it was down.
- Restored redundancy: confirming a new standby catches up after the failover, because until then you have no spare.
- Data integrity: compare row counts or checksums across replicas, and look for writes made during the event.
- Split brain: partition the network so both sides believe they are primary, then confirm fencing or quorum stops the second writer.
Check the numbers against objectives
After each test, compare measurements with the plan.
| Measure | Objective | Measured | Result |
|---|---|---|---|
| Recovery time | 60 s | 95 s | Fail. Health check interval was too long. |
| Data lost | 5 s of writes | 0 s | Pass. |
| Error rate during event | Below 1% | 3% | Fail. Clients cached the old address. |
Failures here are the point of the exercise. Each one becomes a tracked action item with an owner, and the test is rerun after the fix.
Keeping tests useful over time
- Automate drills and run them on a schedule, such as monthly, so drift is caught early.
- Run lightweight fault injection in continuous integration or in production with small blast radius.
- Rerun tests after changes to topology, replication settings, or health check parameters.
- Keep runbooks next to the code, and update them after every test.
- Rotate who leads responses so knowledge does not sit with one person.
- Track results over time: detection time, recovery time, and the number of manual steps should trend down.
Common mistakes
- Testing only the happy case of a clean process stop, not partitions, slowness, or partial failure.
- Running tests without measuring, so nobody can say whether the objective was met.
- Skipping abort conditions, which turns an experiment into an outage.
- Treating a passed test as permanent. Systems change, so results expire.
- Blaming individuals in reviews, which teaches teams to hide problems.
Exercise
Your team's objective is an RTO of 60 seconds and an RPO of 5 seconds for a database with asynchronous replication. Design one fault injection experiment that checks both. State the hypothesis, the fault, two abort conditions, and what you will measure.
Show answer
Hypothesis: if the primary host is terminated under normal write load, a replica is promoted and accepts writes within 60 seconds, and at most 5 seconds of committed writes are missing. Fault: terminate the primary host while a load generator writes records with increasing sequence numbers. Abort conditions, for example: application error rate above 5% for 2 minutes, or no new primary elected after 3 minutes. Measure: time from termination to the first successful write on the new primary (compare with 60 s), and the gap between the last sequence number acknowledged to the client and the last one present on the new primary (convert to time, compare with 5 s). Also record replication lag just before the fault, time to detect, and how long the system ran without a standby.
Exercise
Why is pausing a primary process with SIGSTOP and resuming it later a better fencing test than killing it?
Show answer
A killed process never writes again, so it cannot show whether fencing works. A paused process comes back after the new primary has been promoted and still believes it is primary, so it attempts stale writes. The test passes only if the storage or quorum rejects those writes, for example through a stale fencing token.