Database Optimization
Databases are often among the largest and most sensitive costs in a workload. This lesson explains the components of database cost and the techniques engineers use to reduce them: sizing, capacity models, read scaling, environment policies, query efficiency, licensing and commitments.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the components of database cost.
- Explain how to rightsize databases.
- Choose a database capacity model for a load pattern.
- Explain how read replicas and caching reduce cost.
- Describe cost policies for non-production databases.
- Describe licensing and commitment options for databases.
Where database cost comes from
Managed database cost has several components. The following terms describe them.
- Compute
- The instance class and number of instances, including standby and read replicas.
- Storage
- Allocated or consumed storage, plus provisioned IOPS or throughput for some storage types.
- I/O and requests
- Charges per read and write operation or per request unit on some engines and serverless options.
- Backups
- Backup storage beyond any free allowance, and snapshots retained for long periods.
- Data transfer
- Replication across zones or regions and traffic to clients in other zones.
- Licenses
- For commercial engines, license-included pricing or bring your own license.
Rightsizing databases
Databases can be oversized like any compute, but rightsizing them needs more care. Many engines use available memory as a cache, so memory utilization often looks high even when the database could run with less, while CPU may look low. Useful signals include cache hit ratios, the size of the working set, I/O wait and query latency. Commercial engines licensed per core make rightsizing especially valuable, because every core removed reduces both infrastructure and license cost.
Choosing the capacity model
Databases are offered with different capacity models. The following comparison sets out when each fits.
Database capacity models
Scaling reads and caching
Read-heavy workloads often scale the primary instance up to handle load, which is expensive. Read replicas spread read queries across smaller instances, and an in-memory cache in front of the database serves repeated reads without touching it at all. A cache with a high hit ratio can allow a much smaller primary, reducing cost and latency together.
The following diagram compares a larger database with a smaller one behind a cache.

Non-production databases and query efficiency
Non-production databases rarely need high availability, production backup retention or 24-hour running. Single-zone deployments, smaller classes, shorter retention and schedules, or databases that can be stopped when unused, reduce their cost substantially.
Inefficient queries drive CPU, memory and I/O. Missing indexes, queries that scan whole tables and chatty access patterns from applications can force a larger instance or generate large I/O charges. Query tuning is a cost optimization as well as a performance one.
Licensing and commitments
For commercial engines, the choice between license-included pricing, bring your own license and migrating to an open-source engine can change cost more than any sizing decision. Migration to another engine requires effort and testing, so it needs a business case.
Steady database usage can also be covered by commitment discounts, such as reserved database instances, or on AWS by Database Savings Plans, introduced in December 2025, which apply to eligible usage across several managed database services. As with compute, rightsize before committing.
A cache instead of a bigger database
A product catalog database runs on a large instance at USD 4,800 a month with 70% CPU at peak, almost all from repeated reads of the same products. The team plans to move to an instance twice the size. What alternative should it consider?
An in-memory cache for product reads. If the cache serves most repeated reads, database CPU falls sharply and the team may be able to move to a smaller instance instead of a larger one. A cache costing, say, USD 600 a month that allows a USD 2,400 instance would cost USD 3,000 in total, compared with about USD 9,600 for the larger instance, and would reduce read latency.
Test databases
Twelve test databases are deployed exactly like production: multi-zone, large instances, running continuously, with 35 days of backups. What changes should be considered?
Use single-zone deployments, which can roughly halve instance cost compared with multi-zone; choose smaller instance classes sized for test load; stop the databases outside working hours or use serverless capacity that scales down when idle; and reduce backup retention to a few days, because test data can be recreated. Each change should be confirmed with the teams that use the databases.
Which capacity model suits a database that is busy for two hours a day and nearly idle otherwise?
Show answer
A serverless or autoscaling capacity model, which scales down when idle, rather than a provisioned instance that charges full price around the clock.
Exam Tips
Remember for the exam
- Database cost includes compute, storage, I/O, backups, transfer and licenses.
- Match the capacity model to the load: provisioned, serverless or request-priced.
- Use read replicas and caching before scaling the primary up.
- Non-production databases rarely need multi-zone, long retention or 24-hour running.