Sub topic 3
Scaling and Operating Amazon RDS
Assume you understand SQL, AWS CLI, VPCs, subnets, and security groups. This chapter focuses on read scaling and the operational choices around it.
Scaling reads with read replicas
A read replica is an asynchronous copy of an RDS database. Applications send SELECT queries to the replica while writes continue on the primary instance. Replication lag means recent writes might not be immediately visible.
aws rds create-db-instance-read-replica \
--db-instance-identifier demo-pg-replica \
--source-db-instance-identifier demo-pgUse read replicas for read scaling, reporting, or migrations. Do not use them as the primary high-availability mechanism. Multi-AZ provides synchronous standby failover; read replicas provide additional read capacity.
Tuning with parameter groups
A parameter group contains engine settings. Use a custom group rather than changing the default group.
aws rds create-db-parameter-group \
--db-parameter-group-name demo-pg16 \
--db-parameter-group-family postgres16 \
--description "Custom parameters for demo-pg"
aws rds modify-db-parameter-group \
--db-parameter-group-name demo-pg16 \
--parameters "ParameterName=log_min_duration_statement,ParameterValue=500,ApplyMethod=immediate"Some parameters apply immediately. Others require a reboot. Test changes before applying them to production.
Monitoring and Performance Insights
CloudWatch reports metrics such as CPU usage, free storage, database connections, read latency, write latency, and replica lag. Performance Insights helps identify which database waits and SQL statements consume time. Create alarms for symptoms that need action, especially low storage and high replica lag.
Maintenance and upgrades
Set maintenance and backup windows outside peak traffic. Test engine upgrades and parameter changes on a restored snapshot. An upgrade can require downtime, and replicas may need compatible engine versions.
Pooling connections with RDS Proxy
RDS Proxy pools and reuses database connections. It helps applications that create many short-lived connections, such as serverless functions. It can also reduce connection storms during failover. The proxy adds cost and another endpoint, so use it when connection management is a real bottleneck.
When to consider Aurora instead
Aurora is an AWS-managed relational engine compatible with MySQL or PostgreSQL. It separates compute from distributed storage and offers different scaling and availability options. Compare its cost, compatibility, regional features, and operational requirements with standard RDS before migrating.
Controlling cost and cleaning up
Replicas, Performance Insights, storage, snapshots, and proxy capacity can all add charges. Delete temporary instances and replicas after testing.
aws rds delete-db-instance \
--db-instance-identifier demo-pg-replica \
--skip-final-snapshotExercise
Which feature should you choose for read scaling, and which for automatic failover of the primary?
Show answer
Choose a read replica for read scaling. Choose a Multi-AZ deployment for automatic primary failover.