Sub topic 9
Highly available databases: RDS Multi-AZ and Aurora
The application tier can lose an Availability Zone (AZ) and recover by replacing instances. A database holds state, so it needs a different approach. This chapter covers the options AWS offers for a relational data tier, how each one fails over, and the mistakes that make failover slower or less safe than expected.
This chapter assumes you know what an AZ is, have a VPC with subnets in at least two AZs, and can run AWS CLI commands. You should also know what a DB subnet group is (a set of subnets, in at least two AZs, where RDS may place instances).
The three options
| Option | Copies of data | Standby readable? | Typical failover | Engines |
|---|---|---|---|---|
| RDS Multi-AZ instance deployment | Primary plus one standby in another AZ | No | About 60 to 120 seconds | MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, Db2 |
| RDS Multi-AZ DB cluster | Writer plus two readable standbys in three AZs | Yes | Usually under 35 seconds | MySQL, PostgreSQL |
| Aurora | Six storage copies across three AZs, plus up to 15 reader instances | Yes | Usually under 60 seconds, often faster | Aurora MySQL, Aurora PostgreSQL |
Failover times are typical figures from AWS documentation. Your numbers depend on engine, transaction load, and client behavior, so measure them (see the testing section below).
How RDS Multi-AZ instance deployments work
In this model, RDS runs a primary instance in one AZ and a standby in a second AZ. Storage writes are replicated synchronously to the standby, so a commit is acknowledged only after the standby has the data. This gives a recovery point objective (RPO) of zero for an AZ failure.
Your application connects to a DNS endpoint, not to an IP address. On failover, RDS promotes the standby and updates the DNS record (a CNAME) to point to it. RDS triggers failover automatically when it detects:
- an AZ outage or loss of the primary's host,
- an instance failure or storage failure on the primary,
- a change of instance class or a patching operation,
- a manual reboot with failover.
The standby accepts no connections. You pay for its capacity but cannot send reads to it. If you need read scaling, add read replicas, which are separate asynchronous copies.
To convert an existing single-AZ instance:
aws rds modify-db-instance \
--db-instance-identifier mydb \
--multi-az \
--apply-immediatelyRDS takes a snapshot, builds the standby from it, and then synchronizes. The instance stays available during this, though you may see some added I/O latency. Without --apply-immediately, the change waits for the next maintenance window.
Aurora's different model
Aurora separates compute from storage. One cluster volume is shared by all instances in the cluster, and it keeps six copies of your data across three AZs. Aurora tolerates the loss of an entire AZ plus one more copy without losing write availability.
Because storage is already replicated, Aurora replicas do not replicate data themselves. They read from the same volume, so replica lag is usually in the tens of milliseconds. A failover only needs to promote a reader to writer, not copy any data.
Aurora provides these endpoints:
- The cluster endpoint always points to the current writer.
- The reader endpoint load-balances across readers.
- Instance endpoints point to one specific instance. Avoid these in application config, because they do not follow a failover.
Each reader has a failover priority from tier 0 (first choice) to tier 15. Aurora promotes the reader with the best priority and, among equals, the largest instance size. Give your largest reader tier 0 so a promoted writer can carry the full load.
The no-replica trap
An Aurora cluster with a single instance technically spans three AZs at the storage layer, so your data survives an AZ loss. Your compute does not. If the writer's AZ fails, Aurora must create a new instance, which takes several minutes and may require capacity in a surviving AZ. For production, always run at least one reader in a different AZ from the writer. This is static stability applied to the database: the standby capacity exists before the failure, so recovery does not depend on launching anything during it.
Multi-AZ DB clusters
RDS Multi-AZ DB clusters sit between the two models above. A writer and two readable standbys run in three AZs. A commit succeeds once at least one standby confirms it. Failover is faster than the instance deployment, and you get a reader endpoint for read traffic. Choose this option for MySQL or PostgreSQL when you want faster failover and readable standbys but do not want Aurora's storage model or pricing.
Choosing between them
Use these criteria in order:
- Engine requirement. Oracle, SQL Server, or Db2 limits you to the Multi-AZ instance deployment.
- Failover target. If a minute or two of write unavailability is acceptable, the instance deployment is the simplest and cheapest. If not, consider a Multi-AZ DB cluster or Aurora.
- Read scaling. Aurora supports up to 15 low-lag readers. A Multi-AZ DB cluster gives two.
- Cost. Aurora bills for storage and I/O differently from RDS, so estimate your own workload before assuming one is cheaper.
Making failover work for your application
The database failing over is only half of recovery. The other half is your clients noticing.
- Use the endpoint, never an IP. Resolved addresses become wrong after failover.
- Respect DNS TTL. Some runtimes cache DNS indefinitely. The Java virtual machine can do this when a security manager is installed, so set the network address cache TTL to a small value such as 30 seconds or less.
- Retry with backoff. Existing connections drop at failover. Your connection pool must discard dead connections and reconnect, and your code must retry idempotent operations.
- Consider RDS Proxy. It holds a pool of connections to the database and keeps client connections open while it reconnects to the new primary. This can cut failover disruption noticeably.
- Set sensible timeouts. A connect timeout of several minutes turns a 60-second failover into a long outage for the caller.
Testing failover
Practice the failure before it happens by itself. For a Multi-AZ instance deployment, force a failover with a reboot:
aws rds reboot-db-instance \
--db-instance-identifier mydb \
--force-failoverThe --force-failover flag works only on Multi-AZ instance deployments. For Aurora and Multi-AZ DB clusters, use the cluster command:
aws rds failover-db-cluster \
--db-cluster-identifier myclusterWhile the failover runs, run a loop that writes a row every second and logs errors. Record how long writes failed and whether your pool recovered without a restart. Compare that figure to your recovery time objective (RTO).
Common errors
- Believing Multi-AZ is a backup. A synchronous standby copies a bad
DELETEor a corrupted row just as faithfully as good data. Keep automated backups and point-in-time recovery enabled, and consider Aurora backtrack or snapshot copies for logical errors. - Reading from the standby. In an instance deployment the standby cannot serve reads. Read replicas are a separate feature.
- Pinning to an instance endpoint. In Aurora, an instance endpoint stops being the writer after failover.
- Subnet group in one AZ. Multi-AZ needs a DB subnet group covering at least two AZs, and Aurora benefits from three.
- Undersized standby or reader. If the promoted node has less capacity than the old writer, the failover succeeds but the database is overloaded afterward.
- Assuming zero downtime. Every option here has a window where writes fail. Design the application to tolerate it.
Exercise
Your production Aurora PostgreSQL cluster has one writer instance in AZ A and no readers. A teammate says it is highly available because Aurora stores six copies of data across three AZs. What is wrong with that claim, and what is the smallest change that fixes it?
Show answer
The six storage copies protect the data, but the compute is a single writer in AZ A. If AZ A fails, Aurora must create a new instance during the outage, which takes several minutes and depends on capacity being available. The smallest fix is to add one Aurora reader in a different AZ (for example AZ B) and give it failover priority tier 0. Then a reader already exists and can be promoted in under a minute, without launching anything during the failure.
Exercise
After a forced failover on a Multi-AZ RDS instance, your Java application keeps failing for 20 minutes until you restart it. Database logs show the failover finished in 90 seconds. Name two likely causes and a fix for each.
Show answer
First, the JVM cached the old DNS answer for the endpoint, so clients kept connecting to the former primary's address. Fix it by setting a short DNS cache TTL (for example 30 seconds or less). Second, the connection pool kept dead connections and did not validate or evict them. Fix it by enabling connection validation or a max connection lifetime, adding retries with backoff, and optionally placing RDS Proxy in front of the database.