Sub topic 12
Running failover and failback
This chapter assumes you know the four DR strategies (backup and restore, pilot light, warm standby, multi-site active/active) and have seen Route 53 failover records and Aurora global databases. It covers what happens on the day you use the standby Region, and the day you return to the original one.
Failover and failback are separate operations
Failover moves production from the primary Region to the recovery Region. Failback moves it back. Teams often write a careful failover runbook and leave failback as "we'll figure it out later." That is a mistake, because failback has its own data and traffic problems:
- Writes made in the recovery Region must reach the original Region before you switch back. If they don't, you lose them.
- The original Region may be only partly recovered. Some services come back before others.
- Failback is usually planned, so you can pick the time. That makes it a lower-risk operation than failover, but only if you treat it as a real procedure.
Failover: the decision
The first hard step is the decision to fail over. Automated health checks detect symptoms, but a person with authority usually declares the disaster. The reason is cost. A failover can lose data (up to your RPO) and takes time (up to your RTO). A false alarm that triggers a full failover is itself an outage.
Write down in advance:
- Who may declare a disaster, and who is their backup.
- The triggers, such as "primary Region unavailable for 15 minutes with no AWS estimate of recovery."
- The communication channel that does not depend on the failed Region. If your chat tool or runbook wiki runs in the primary Region, you cannot read the runbook.
Failover: the order of operations
Do the steps in dependency order. Data comes first, because everything else needs a writable database.
| Step | Action | Backup and restore | Pilot light | Warm standby | Active/active |
|---|---|---|---|---|---|
| 1 | Make data writable in the DR Region | Restore from backup | Promote replica | Promote replica | Already writable |
| 2 | Provide compute | Deploy with IaC | Scale up the dormant fleet | Scale up to full size | Already running |
| 3 | Verify the application | Smoke test | Smoke test | Smoke test | Check capacity |
| 4 | Shift traffic | DNS change | DNS change | DNS change | Remove the failed Region from rotation |
The following commands cover steps 1 and 2 for pilot light and warm standby. Both use the DR Region (us-west-2) and its own API endpoint.
# Step 2: scale the dormant DR Auto Scaling group up from its minimal size
aws autoscaling update-auto-scaling-group \
--region us-west-2 \
--auto-scaling-group-name app-dr \
--min-size 4 \
--desired-capacity 4 \
--max-size 12
# Step 1 (planned): switch the Aurora global database primary to the DR Region
aws rds failover-global-cluster \
--region us-west-2 \
--global-cluster-identifier app-global \
--target-db-cluster-identifier arn:aws:rds:us-west-2:111122223333:cluster:app-dr-clusterThe failover-global-cluster command above runs as a switchover. A switchover waits for the secondary to catch up, so no data is lost. It needs both Regions to be healthy, so it suits drills and planned moves.
In a real Region outage the primary cannot cooperate. Add --allow-data-loss to run a true failover, which promotes the secondary at whatever point replication had reached. The data you lose is the replication lag at the moment of the failure. Check the AuroraGlobalDBReplicationLag CloudWatch metric afterward and record the actual loss, because that is your measured RPO.
Other data stores have their own promotion steps:
- RDS cross-Region read replica: promote it. This is one-way and the replica becomes a standalone instance.
- DynamoDB global tables: nothing to promote. Every replica accepts writes.
- S3 cross-Region replication: nothing to promote, but the application must point at the replica bucket.
Failover: shifting traffic
Traffic is the last step. If you shift it before the database is writable and the fleet is scaled, users see errors from a Region you declared healthy.
With Route 53 failover records, the secondary record answers when the primary's health check fails. The records use a 60-second TTL, so clients can take up to a minute or more to move. Resolvers and client libraries that cache DNS longer than the TTL extend this.
There is a trap. Route 53's control plane, which handles changes such as change-resource-record-sets, runs in us-east-1. If that Region is your failed primary, the API you planned to call may be impaired. Health-check evaluation and DNS answers (the data plane) keep working. Your runbook should therefore prefer actions that need no control-plane call:
- Let the health check fail over automatically.
- Use Route 53 Application Recovery Controller routing controls, which you flip through a highly available data plane cluster endpoint.
- Use Global Accelerator, where you shift a traffic dial on the endpoint group. Clients keep the same static anycast IP addresses, so DNS caching does not delay them.
After failover: stabilize
Once traffic is in the DR Region, check the following before declaring recovery complete:
- Dependencies outside the data stores: secrets, KMS keys, parameter values, third-party endpoints, and allow-lists that contain primary-Region IP addresses.
- Capacity limits. Service quotas in the DR Region may be lower than in the primary. Scaling a pilot light fleet to production size can hit an EC2 vCPU quota or a lack of available instances of your type. Raise quotas before the incident, and consider On-Demand Capacity Reservations for the capacity you must have.
- Background jobs and schedulers. Cron-style jobs should run in one Region only, or they will process work twice.
- Monitoring and alarms. Dashboards and alarms in the DR Region must exist and point to the right resources.
Failback: returning to the primary Region
Wait until the primary Region is stable. Then work through these steps:
- Rebuild the primary. Use the same infrastructure as code that built the DR environment. Never rebuild by hand.
- Reverse data replication. The DR Region now holds the newest data. Make the original Region a replica of it. For Aurora global database, the original cluster must rejoin the global cluster as a secondary. If the failover used
--allow-data-loss, the old primary was detached and diverged, so you create a fresh secondary from the current primary rather than reattach the old data. - Wait for sync. Do not switch until lag is near zero.
- Schedule a window. Failback is planned, so pick a low-traffic time and announce it.
- Switch back. Run a switchover, then shift traffic.
- Restore the standby. Scale the DR fleet back down to its normal posture, and re-establish replication in the original direction.
# Confirm which cluster is the writer and that the original Region has rejoined
aws rds describe-global-clusters \
--region us-west-2 \
--global-cluster-identifier app-global \
--query 'GlobalClusters[0].GlobalClusterMembers[].[DBClusterArn,IsWriter]' \
--output table
# Planned switchover back to the original primary cluster (no data loss)
aws rds failover-global-cluster \
--region us-west-2 \
--global-cluster-identifier app-global \
--target-db-cluster-identifier arn:aws:rds:us-east-1:111122223333:cluster:app-primary-clusterSome teams choose never to fail back. They treat the DR Region as the new primary and build a new standby in the old Region. This is simpler when both Regions are equivalent, and it avoids a second cutover. It fails if the DR Region was sized or located as a compromise.
Common mistakes
- Untested runbook steps. A command that needs a parameter nobody remembers wastes minutes when the RTO is short.
- Split brain. Both Regions accept writes to a non-multi-writer store after a partial failure. Fence the old primary, for example by denying it write access, before promoting the new one.
- Forgetting failback data. Writes made during the outage exist only in the DR Region. Replicating back overwrites the old primary's divergent copy, so first decide whether any data from that copy must be merged.
- DNS caching. A TTL of 60 seconds does not guarantee that clients move in 60 seconds.
Exercise
Your primary Region fails and you run aws rds failover-global-cluster without --allow-data-loss. The primary cannot respond. What is the likely result, and what should you do instead?
Show answer
Without --allow-data-loss the command is a switchover, which needs a healthy primary and waits for the secondary to catch up, so it will not complete during a real outage. Run it with --allow-data-loss to promote the secondary immediately, accept that you lose the replication lag at the time of failure, and record that lag as your measured RPO.
Exercise
Name two reasons a runbook should avoid depending on Route 53 change-resource-record-sets during a failover from us-east-1, and give one alternative.
Show answer
The Route 53 control plane runs in us-east-1, so the API may be impaired when that Region is the one failing, and the change still waits on DNS caching before clients see it. Use automatic health-check failover, Application Recovery Controller routing controls, or the Global Accelerator traffic dial instead.