RDS and Aurora
Amazon Relational Database Service (RDS) runs relational databases for you: MySQL, PostgreSQL, MariaDB, Oracle, Microsoft SQL Server and Db2. You choose the engine, instance size and storage; AWS handles provisioning, OS and engine patching, automated backups, failover and monitoring. You still design the schema, write the queries and control who can connect.
Amazon Aurora is AWS's own MySQL- and PostgreSQL-compatible engine, rebuilt for the cloud: storage is shared across three AZs with six copies of the data, it grows automatically, and failover is fast.
Self-managed vs RDS
| Task | Database on EC2 | RDS / Aurora |
|---|---|---|
| Install and patch OS and engine | You | AWS (in your maintenance window) |
| Backups and point-in-time restore | You script it | Automatic, retention 1–35 days |
| High availability | You build replication and failover | Multi-AZ checkbox |
| Read scaling | You set up replicas | Read replicas with one call |
| Schema, queries, indexes, users | You | You |
| SSH access to the host | Yes | No (except RDS Custom) |
Creating a database
aws rds create-db-instance --db-instance-identifier shop-db \
--engine postgres --engine-version 17 --db-instance-class db.t4g.medium \
--allocated-storage 50 --storage-type gp3 \
--master-username shopadmin --manage-master-user-password \
--multi-az --backup-retention-period 7 \
--vpc-security-group-ids sg-0db1234567890abcd --db-subnet-group-name private-db-subnets \
--no-publicly-accessible
aws rds describe-db-instances --db-instance-identifier shop-db \
--query "DBInstances[0].[DBInstanceStatus,Endpoint.Address,MultiAZ]"Sample output:
[
"available",
"shop-db.c9akciq32.eu-west-1.rds.amazonaws.com",
true
]--manage-master-user-password stores the password in AWS Secrets Manager instead of on your command line.
Multi-AZ vs read replicas
These are often confused. They solve different problems:
| Multi-AZ | Read replicas | |
|---|---|---|
| Purpose | Availability (survive an AZ or instance failure) | Read scaling (spread SELECT load) |
| Replication | Synchronous to a standby | Asynchronous (replicas can lag) |
| Can you query the standby? | No (classic Multi-AZ instance); yes for the readable standbys of a Multi-AZ DB cluster | Yes |
| Failover | Automatic, the DNS endpoint moves | Manual promotion |
| Across Regions | No | Yes (cross-Region replicas) |
Model: routing reads and writes
Applications typically send writes to the primary (writer) endpoint and spread reads over replicas. Asynchronous replication means a read right after a write may see old data:
class Cluster:
def __init__(self, replicas):
self.primary = {}
self.replicas = [dict() for _ in range(replicas)]
self.pending = [] # (apply_at_tick, key, value): replication lag
self.tick = 0
self.next_replica = 0
def write(self, key, value, lag=2):
self.primary[key] = value
self.pending.append((self.tick + lag, key, value))
def advance(self):
self.tick += 1
for item in [p for p in self.pending if p[0] <= self.tick]:
for r in self.replicas:
r[item[1]] = item[2]
self.pending.remove(item)
def read(self, key, consistent=False):
if consistent:
return self.primary.get(key), "primary"
i = self.next_replica % len(self.replicas)
self.next_replica += 1
return self.replicas[i].get(key), f"replica-{i}"
db = Cluster(replicas=2)
db.write("order:7", "paid")
print("t=0", db.read("order:7"), db.read("order:7", consistent=True))
db.advance(); print("t=1", db.read("order:7"))
db.advance(); print("t=2", db.read("order:7"), db.read("order:7"))t=0 (None, 'replica-0') ('paid', 'primary')
t=1 (None, 'replica-1')
t=2 ('paid', 'replica-0') ('paid', 'replica-1')
Right after the write, the replica returns None (stale), while the primary already has the value. Reads that must see the latest data ("show my order right after I placed it") should go to the writer.
Model: Multi-AZ failover
def multi_az(events):
primary, standby = "eu-west-1a", "eu-west-1b"
for event in events:
if event == f"{primary} fails":
primary, standby = standby, None
print(f"{event:<22} -> failover: DNS endpoint now points to {primary}, ~1-2 min")
elif event == "replace standby":
standby = "eu-west-1c"
print(f"{event:<22} -> new standby created in {standby}")
else:
print(f"{event:<22} -> no impact (primary {primary}, standby {standby})")
multi_az(["eu-west-1c network blip", "eu-west-1a fails", "replace standby"])eu-west-1c network blip -> no impact (primary eu-west-1a, standby eu-west-1b)
eu-west-1a fails -> failover: DNS endpoint now points to eu-west-1b, ~1-2 min
replace standby -> new standby created in eu-west-1c
The application keeps using the same endpoint name; only the IP behind it changes. Apps must reconnect after a failover, so use connection retry logic.
Aurora highlights
- Up to 15 low-lag Aurora Replicas sharing the same storage volume.
- A cluster endpoint for writes and a reader endpoint that load-balances replicas.
- Aurora Serverless v2 scales capacity in fine steps (ACUs) with load.
- Aurora Global Database replicates to other Regions with typically under one second of lag.
Backups
Automated backups plus transaction logs allow point-in-time restore to any second within the retention period. Manual snapshots are kept until you delete them. A restore always creates a new DB instance.
Test yourself
Which RDS feature mainly improves AVAILABILITY?
- Read replicas
- Multi-AZ deployment
- Performance Insights
- Parameter groups
Why can a read replica return old data right after a write?
- Replicas are read-only
- Replication to read replicas is asynchronous
- Replicas use a different engine
- The cache is full
Which is still YOUR responsibility on RDS?
- Patching the database engine
- Replacing failed hardware
- Designing the schema and indexes
- Operating system updates