Handbooks / AWS / Chapter 4
RDS and DynamoDB
6 pages · ~4 min✓ Reviewed
Builds on S3. Next up: Load Balancing and Auto Scaling.
AWSPage 1RDS Engines, Multi-AZ and Read Replicas
1. What RDS Is
- Managed relational DB, no OS or SSH access
- MySQL, PostgreSQL, MariaDB, Oracle, SQL Server, Db2
- Aurora: MySQL/PostgreSQL-compatible, 6 copies across 3 AZs, grows to 256 TiB
2. Multi-AZ vs Read Replica
- Primary fails
- DNS flipssame endpoint
- Standby serves~1-2 min
- Multi-AZ DB cluster (two readable standbys) is the exception: standbys serve reads
- Replicas: up to 15 (MySQL/PostgreSQL/MariaDB, Aurora), 5 (Oracle, SQL Server)
- Replica can be promoted to a standalone DB; lag is possible
3. Mistakes
- Counting a replica as your failover
- Sending writes to a replica
- Expecting strictly fresh async reads
4. Interview Point
- Multi-AZ for scaling? No, HA only; standby serves no reads
- Cross-Region read DR? Cross-Region read replica
- Stale replica read? Async replication lag
- Endpoint on failover? Same DNS name flips to standby
AWSPage 2RDS Backups and Recovery
- PITR restores to any second in the window
- Retention
0 turns automated backups off
2. Restore and Copy
- Snapshot or PITR
- New instance
- New endpoint
- Repoint app
- Snapshots copy across Regions
- Snapshots share across accounts
- Encryption cannot be removed from a DB
Encrypt an unencrypted DB- 1Snapshot
- 2Copy with KMS key
- 3Restore the copy
AWSPage 3DynamoDB Tables, Keys and GSIs
1. Keys
- Serverless key-value/document NoSQL, single-digit-ms latency
- Item limit 400 KB
- Primary key: partition key, or partition + sort key
- Partition key is hashed to pick the partition
- Good: high-cardinality, evenly accessed key
- Bad:
status or date → hot partition, throttling
2. Query vs Scan
- Sort key orders items in a partition
- Query: one partition key, plus
begins_with, between, ordering - Scan: whole table, slow, costly, avoid in production
pythontable.query(
KeyConditionExpression=Key('pk').eq('u1')
& Key('sk').begins_with('ORDER#')) one partition, sort-key prefix
AWSPage 4Capacity Modes and Choosing RDS vs DynamoDB
- 1 RCU = one strongly consistent 4 KB read/s (two eventually consistent)
- 1 WCU = one 1 KB write/s
- 100 strong reads of 8 KB/s = 2 RCU each = 200 RCU
- Provisioned → on-demand: 4 times per rolling 24 h; back: any time
- Over limit:
ProvisionedThroughputExceededException, retry with backoff
AWSPage 5AWS Databases Cheat Sheet
1. RDS: HA, Replicas, Backups
- Automated backups: 1-35 days (default 7), PITR
- Manual snapshots persist after delete
- Every restore makes a new instance
2. DynamoDB Keys
- Partition key hashed: keep it even
- Sort key enables Query ranges; avoid
Scan - GSI: add anytime, eventually consistent
- LSI: only at table creation
An RDS Multi-AZ instance has slow reports. You expect the standby in the other AZ to share the read load. Will it?
- No: the standby serves no reads; it only waits for failover.
- Add a read replica for reads (async, so results may lag).
A bad DELETE ran 10 minutes ago. Automated backups are on. What do you do, and what happens to the endpoint?
- Run a point-in-time restore to just before the DELETE.
- It creates a new instance with a new endpoint, so repoint the app. The old one is untouched.
How many RCUs for 100 strongly consistent reads per second of 8 KB items?
- 8 KB is 2 units of 4 KB, so 100 × 2 = 200 RCU.
- Eventually consistent would need only 100.