Database Performance: RDS, Aurora, DynamoDB and ElastiCache
Overview
A slow database slows the whole application. SysOps administrators diagnose performance by asking four questions: is the problem CPU, memory, I/O or connections? Is it caused by a specific query? Is the system throttled by provisioned capacity? And could a cache or replica remove the load?
Imagine a restaurant kitchen. If every order requires the head chef (CPU), if the fridge is a long walk away (I/O), if too many waiters crowd the pass (connections), or if one complicated dish blocks everyone (slow query), diners wait. The tools below help you find which bottleneck you have.
AWS offers Performance Insights, Enhanced Monitoring, CloudWatch metrics, slow query logs and DynamoDB throttling metrics to pinpoint the cause.
Key Concepts
- Performance Insights shows database load (average active sessions, AAS) broken down by SQL, wait event, host and user; compare AAS to vCPU count.
- Enhanced Monitoring provides OS-level metrics (per-process CPU, memory, I/O) at up to 1-second granularity from an agent on the DB host.
- RDS CloudWatch metrics: CPUUtilization, FreeableMemory, SwapUsage, ReadIOPS/WriteIOPS, ReadLatency/WriteLatency, DiskQueueDepth, DatabaseConnections, FreeStorageSpace, ReplicaLag.
- Parameter groups tune engine settings (e.g. max_connections, innodb_buffer_pool_size); static parameters need a reboot, dynamic apply immediately.
- Fixes: scale instance class, add read replicas, use RDS Proxy to pool connections, add indexes, enable storage autoscaling and move to gp3/io2 or Aurora.
- DynamoDB: provisioned vs on-demand capacity; ThrottledRequests / ProvisionedThroughputExceeded indicate throttling; hot partitions; use Application Auto Scaling, DAX and adaptive capacity.
- ElastiCache (Redis/Valkey, Memcached) offloads reads; watch CacheHitRate, Evictions, CPUUtilization, EngineCPUUtilization, Memory.
- Enable slow query and error logs (publish to CloudWatch Logs); use DevOps Guru for RDS for ML-based anomaly insights.
Detailed Notes
Diagnosing RDS performance
| Symptom | Likely cause | Remedy |
|---|---|---|
| High CPU, AAS > vCPUs | Inefficient queries, too small class | Tune SQL/indexes (Performance Insights), scale up |
| Low FreeableMemory + swap | Memory pressure, too many connections | Larger instance, reduce connections/parameters, RDS Proxy |
| High DiskQueueDepth / latency | I/O bound | Provisioned IOPS/gp3, larger storage, optimise queries |
| DatabaseConnections at limit | Connection storms (Lambda!) | RDS Proxy, pooling, raise max_connections |
| Replica lag growing | Long transactions, undersized replica | Larger replica, tune, reduce writes |
| FreeStorageSpace low | Growth, binlogs, temp tables | Storage autoscaling, purge logs |
Enabling Performance Insights and logs
aws rds modify-db-instance --db-instance-identifier prod-db \
--enable-performance-insights --performance-insights-retention-period 7 \
--monitoring-interval 15 --monitoring-role-arn arn:aws:iam::111122223333:role/rds-monitoring \
--cloudwatch-logs-export-configuration '{"EnableLogTypes":["slowquery","error"]}' \
--max-allocated-storage 1000 --apply-immediately
--max-allocated-storage turns on storage autoscaling (grows when free space < 10%, and 6 hours since last change).
Parameter group changes
aws rds create-db-parameter-group --db-parameter-group-name mysql-prod --db-parameter-group-family mysql8.0 --description prod
aws rds modify-db-parameter-group --db-parameter-group-name mysql-prod \
--parameters "ParameterName=slow_query_log,ParameterValue=1,ApplyMethod=immediate" \
"ParameterName=long_query_time,ParameterValue=1,ApplyMethod=immediate"
aws rds reboot-db-instance --db-instance-identifier prod-db # needed for pending-reboot parameters
RDS Proxy
Pools and shares database connections, reduces failover time (up to ~66%), enforces IAM authentication, and stores credentials in Secrets Manager. Ideal for Lambda and apps with spiky connections.
DynamoDB capacity and throttling
| Mode | When |
|---|---|
| On-demand | Unpredictable traffic; pay per request |
| Provisioned + auto scaling | Predictable traffic; cheaper at steady usage; reserved capacity discounts |
aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB --metric-name ThrottledRequests \
--dimensions Name=TableName,Value=orders --statistics Sum --period 60 \
--start-time 2025-03-01T10:00:00Z --end-time 2025-03-01T11:00:00Z
aws application-autoscaling register-scalable-target --service-namespace dynamodb \
--resource-id table/orders --scalable-dimension dynamodb:table:WriteCapacityUnits --min-capacity 5 --max-capacity 500
Throttling causes: provisioned capacity exceeded, hot key/partition, large items, scans, GSI throttling (a throttled GSI also throttles table writes). Fix with better key design, adaptive capacity, on-demand mode, exponential backoff and DAX for read-heavy cache.
ElastiCache metrics
| Metric | Meaning |
|---|---|
| CacheHitRate | Low -> poor key design/TTL; |
| Evictions > 0 | Memory too small -> scale up/out |
| EngineCPUUtilization | Redis single-thread bottleneck -> shard or scale up |
| CurrConnections | Connection storms |
| ReplicationLag | Replica staleness |
Caching patterns: lazy loading (cache-aside) and write-through; Redis supports persistence, replication, Multi-AZ auto-failover and cluster mode.
Aurora considerations
Aurora storage auto-grows to 128 TiB, replicas share storage (low lag), Aurora Serverless v2 scales ACUs in fine increments; use reader endpoint for load balancing and custom endpoints for workload isolation.### Parameter groups, maintenance and storage events
| Task | Detail |
|---|---|
| Parameter groups | Dynamic parameters apply immediately; static need a reboot; status shows pending-reboot |
| Snapshots | Automated (retention up to 35 days, point-in-time restore) and manual (kept until deleted) |
| Storage autoscaling | Set a maximum allocated storage so RDS grows automatically |
| Maintenance windows | Patching of minor versions, may cause brief failover on Multi-AZ |
| Enhanced Monitoring | OS-level metrics at 1-60 s granularity |
| Performance Insights | DB load by wait event, SQL, host and user |
| Slow query / error logs | Publish to CloudWatch Logs |
| Blue/Green deployments | Staged environment for upgrades and schema changes with fast switchover |
aws rds modify-db-instance --db-instance-identifier prod-db --max-allocated-storage 2000 --apply-immediately
aws rds modify-db-instance --db-instance-identifier prod-db --cloudwatch-logs-export-configuration EnableLogTypes=slowquery,error
aws rds restore-db-instance-to-point-in-time --source-db-instance-identifier prod-db --target-db-instance-identifier prod-db-restore --use-latest-restorable-time
aws rds create-blue-green-deployment --blue-green-deployment-name upg --source <arn> --target-engine-version 8.0.36
Restores always create a new instance with a new endpoint. Common alarms: FreeStorageSpace, CPUUtilization, DatabaseConnections, ReplicaLag, FreeableMemory and SwapUsage. Encryption must be chosen at creation; to encrypt an existing database restore from an encrypted snapshot copy.
Real World Example
Scenario – Lambda overwhelms the database. A serverless API exhausts the MySQL max_connections during traffic spikes. DatabaseConnections flat-lines at the limit while CPU is low. Performance Insights shows waits on connection handling rather than queries.
The team adds RDS Proxy with credentials in Secrets Manager and points Lambda at the proxy endpoint. Connections stay stable, failover recovery drops from about a minute to seconds, and a read replica handles reporting queries. An ElastiCache cache-aside layer reduces repetitive reads by 70%, and a CloudWatch alarm on CacheHitRate guards regressions.
Architecture Diagram
- 1The application checks the cache first; hits never reach the database.
- 2Misses go through RDS Proxy, which pools and multiplexes connections.
- 3Writes go to the writer; read-only queries use replicas.
- 4Performance Insights and CloudWatch reveal load, waits and slow queries.
Best Practices
- ✓Enable Performance Insights, Enhanced Monitoring and slow query logs on production databases.
- ✓Alarm on CPU, FreeableMemory, DiskQueueDepth, connections, FreeStorageSpace and ReplicaLag.
- ✓Use RDS Proxy for Lambda and connection-heavy apps; offload reads to replicas or cache.
- ✓Enable storage autoscaling with a sensible maximum.
- ✓For DynamoDB design well-distributed keys, use auto scaling/on-demand and handle throttles with backoff.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Find top SQL and wait events -> Performance Insights; OS process view -> Enhanced Monitoring.
- Too many DB connections from Lambda -> RDS Proxy.
- Offload read-heavy workloads -> read replicas / ElastiCache / DAX (DynamoDB).
- Disk full on RDS -> enable storage autoscaling; static parameters need a reboot.
Finished this lesson?
0 of 46 lessons done · 0% of the course

