Sub topic 14
Testing failover and injecting faults
This chapter assumes you have a multi-AZ workload: an Application Load Balancer, an Auto Scaling group across two AZs, and an RDS Multi-AZ database. It also assumes you can read the AWS CLI and YAML. A design that has never been tested is a guess. Failover paths run rarely, so they hide bugs such as stale DNS caches, missing permissions, and connection pools that never reconnect.
Start with a hypothesis
Write down what you expect before you break anything. A useful hypothesis names a fault, a measurable result, and a time limit. For example: "If one AZ loses all its instances, the error rate stays under 1% and p99 latency stays under 800 ms. The database fails over within 120 seconds."
Run the test in a pre-production environment first. In production, start small, keep a stop condition, and tell the people on call.
Test the database failover
A forced failover shows how your application behaves when the standby takes over. The following command reboots the instance and promotes the standby.
aws rds reboot-db-instance \
--db-instance-identifier mydb \
--force-failoverThe database endpoint is a DNS name. After failover it points to the new primary. Watch for these common errors:
- The application caches DNS for too long and keeps connecting to the old address.
- The connection pool keeps dead connections and never retries.
- Writes fail during the failover window and are not retried.
Run a steady load while you do this, and record how long errors last.
Inject faults with AWS Fault Injection Service
AWS Fault Injection Service (FIS) runs controlled experiments. An experiment template lists actions, targets, and stop conditions. A stop condition is a CloudWatch alarm. If it fires, FIS halts the experiment.
Useful faults for AZ testing include:
| Fault | What it simulates |
|---|---|
| Stop or terminate EC2 instances in one AZ | Loss of compute capacity |
| Network disruption on subnets in one AZ | An AZ that is unreachable |
| RDS failover | Loss of the primary database |
| Network latency or packet loss | A degraded, not dead, dependency |
Tag the instances you want to affect. Target them by tag and AZ, so the blast radius stays small.
What to check during a test
- The load balancer stops sending traffic to the failed AZ's targets. Check the health check settings.
- The Auto Scaling group keeps enough capacity in the remaining AZ without needing a manual step. This ties back to static stability.
- Per-AZ metrics show the fault. If you cannot see it, your observability has a gap.
- Recovery happens without anyone calling a control-plane API.
Make it routine
Run these tests on a schedule, not once. Infrastructure and code change, and a design that passed last quarter can fail today. Run them as part of release checks or as regular game days, and fix every gap you find before the next run.
Exercise
You force an RDS failover and your application returns errors for six minutes, although the database was available again after about two minutes. What are two likely causes?
Show answer
The application likely cached the old DNS result for too long, or its connection pool kept dead connections and did not reconnect. Either one keeps requests failing after the new primary is ready. Check the DNS TTL handling and the pool's validation and retry settings.