4.3 Database Cost Optimization
Key Takeaways
- Aurora Serverless v2 scales compute automatically (0.5-256 ACUs) and bills per second, eliminating waste from over-provisioned database instances.
- DynamoDB On-Demand mode charges per read/write request with no capacity planning; Provisioned mode with auto-scaling is cheaper for predictable workloads.
- RDS Reserved Instances save up to 69% for steady-state databases; choose Multi-AZ reserved for production databases.
- ElastiCache Reserved Nodes save up to 55% for always-on caching layers.
- Use read replicas to offload read traffic from the primary database, potentially reducing the primary instance size (and cost).
Database Cost Optimization
Quick Answer: Use Aurora Serverless for variable workloads (pay per ACU-second). Use RDS Reserved Instances for steady-state databases (up to 69% off). Use DynamoDB On-Demand for unpredictable traffic, Provisioned for predictable traffic. Add ElastiCache or DAX to reduce expensive database reads. Read replicas offload read traffic cheaply.
RDS Cost Optimization
Instance Right-Sizing
| Strategy | How |
|---|---|
| Performance Insights | Identify actual CPU, memory, and I/O usage |
| CloudWatch metrics | Monitor CPU utilization, freeable memory, read/write IOPS |
| Compute Optimizer | Get right-sizing recommendations |
| Graviton instances | Switch to Graviton (arm64) for up to 20% cost savings with better performance |
RDS Pricing Options
| Option | Savings | Commitment |
|---|---|---|
| On-Demand | Baseline | None |
| Reserved (1-year) | ~40% | 1 year |
| Reserved (3-year) | Up to 69% | 3 years |
| Aurora Serverless v2 | Variable (per ACU-second) | None |
Read Replicas for Cost Optimization
Instead of scaling UP (larger primary instance), scale OUT with read replicas:
- Offload read queries to replicas (cheaper instances)
- Reduce load on primary → potentially downsize the primary
- Aurora allows up to 15 read replicas with automatic load balancing
Aurora Serverless for Cost Optimization
| Scenario | Provisioned Aurora Cost | Serverless v2 Cost |
|---|---|---|
| Dev/test (used 8 hours/day) | ~$730/month (db.r6g.large 24/7) | ~$245/month (8 hours active + 16 hours idle) |
| Variable workload (spikes 4x baseline) | ~$1,460/month (sized for peak) | ~$500/month (scales dynamically) |
| Steady 24/7 high load | ~$730/month | ~$800/month (overhead from per-ACU pricing) |
Key insight: Aurora Serverless saves money for variable or part-time workloads. For steady 24/7 workloads, provisioned instances with Reserved pricing are cheaper.
DynamoDB Cost Optimization
On-Demand vs. Provisioned
| Mode | Cost (us-east-1) | Best For |
|---|---|---|
| On-Demand | $1.25 per million write requests, $0.25 per million read requests | Unpredictable, spiky traffic |
| Provisioned | $0.00065 per WCU/hour, $0.00013 per RCU/hour | Predictable, steady traffic |
| Provisioned + Reserved | Up to 77% off provisioned pricing | Steady, long-term workloads |
DynamoDB Cost Strategies
| Strategy | How It Saves |
|---|---|
| Use TTL | Automatically delete expired items at no cost (reduces storage) |
| Use DAX | Cache reads to reduce RCU consumption |
| Optimize item size | Smaller items = fewer RCUs/WCUs |
| Use GSI projections | Project only needed attributes in Global Secondary Indexes |
| Reserved Capacity | Commit to provisioned capacity for up to 77% savings |
Caching for Cost Reduction
Adding a caching layer reduces database load, which means:
- Fewer reads hitting the database → lower IOPS/RCU needs → smaller (cheaper) instance
- Better performance → fewer timeouts → fewer retries → lower cost
| Caching Solution | Use With | Cache Hit Latency |
|---|---|---|
| ElastiCache Redis | Any database | Sub-millisecond |
| DynamoDB DAX | DynamoDB only | Microsecond |
| CloudFront | API responses, web content | Millisecond (edge) |
| API Gateway caching | API responses | Millisecond |
On the Exam: "Reduce database costs for a read-heavy workload" → Add ElastiCache or read replicas. "Variable database workload with unpredictable traffic" → Aurora Serverless or DynamoDB On-Demand.
A development database is only used during business hours (8 AM to 6 PM) on weekdays. What is the MOST cost-effective database solution?
A DynamoDB table experiences highly unpredictable traffic — ranging from 10 reads/second to 10,000 reads/second throughout the day. Which capacity mode should they use?