Task 4.3 · 20 min read
Cost-Optimized Databases
Services in this lesson
- Amazon RDSin scope
- Amazon Aurorain scope
- Amazon Aurora Serverlessin scope
- Amazon DynamoDBin scope
- Amazon ElastiCachein scope
- Amazon Redshiftin scope
- Savings Plansin scope
- AWS Cost Explorerin scope
- AWS Budgetsin scope
- AWS Cost and Usage Reportin scope
What the exam tests
- Matching the billing model to the load shape. Provisioned capacity suits a steady baseline, and Aurora Serverless v2 or DynamoDB on-demand suits unpredictable load. Commit only to the part that never goes away.
- Choosing the Aurora storage configuration, Standard or I/O-Optimized, by how much of the bill is I/O.
- Stopping storage and backups from growing without a reason. The levers are free backup allowances and snapshot retention. In DynamoDB, Standard-IA (Standard-Infrequent Access, a cheaper storage class) handles cold data, and TTL (time to live, automatic expiry) handles expiring data.
- Using a cache such as ElastiCache so the database can be smaller, and spotting when a cache saves nothing.
- Picking the database commitment that fits the load, and the term each one needs. The options are Database Savings Plans, RDS reserved DB instances, DynamoDB reserved capacity and ElastiCache reserved nodes.
This lesson owns the cost side of database choices. It asks which database setting meets the requirement for the least money. Other topics live elsewhere:
- How replicas, DAX and the DynamoDB partition key scale performance: task 3.3, high-performing databases.
- How backups are protected and restored: task 1.3, data security.
- Multi-AZ availability and disaster recovery: task 2.2, high availability.
- Compute Savings Plans and EC2 Reserved Instances: task 4.2, cost-optimized compute.
The core concept
A database bill has four parts (compute, storage, I/O and backups), and each has its own lever. Find the part that dominates, commit to the load that never goes away, and pay as you go for the rest.
- Compute runs the database engine. It is priced by the provisioned instance or by the capacity unit.
- Storage holds the data. It is priced by the gigabyte-month (one gigabyte kept for one month) that you allocate or use.
- I/O is each read or write the engine sends to storage. Some Aurora and DynamoDB modes charge for it per request.
- Backups are snapshot copies of the data. You pay for snapshot storage beyond a free allowance.
An analogy: a bakery renting kitchen space
Picture a bakery that rents its kitchen instead of owning one:
- A yearly lease on one oven covers the bread it bakes every single day. That's a commitment sized to the steady floor of the work.
- Renting an oven only when a catering order comes in covers surprise jobs. Each job costs more than the lease rate, but quiet days cost nothing. That's on-demand or Serverless pricing.
- A cheap cold-storage unit holds flour that is rarely touched. Getting a sack out costs a little extra each time. That's an infrequent-access storage class.
- Stock with a best-before date gets thrown out without anyone scheduling it. That's an expiry rule on old data.
- A sign on the counter answers the question every customer asks. The staff stop repeating themselves. That's a cache.
Where the analogy breaks: a lease holds one particular oven for you. A Database Savings Plan or a reserved DB instance holds no capacity at all, and each is only a discount on usage that matches it.
Walk one bill review through it
The diagram is a decision flow. It starts from the data model, splits by load or traffic shape, and ends at the billing setting that fits.
Orchard Ledger sells online bookkeeping to small firms. Lucas runs its finance team, and Sana is its database engineer.
- Lucas flags a rising database bill. Sana starts at the top of the diagram and sorts each database by data model. The ledger is relational (tables that SQL queries join). Sessions and audit events are key-value data (items fetched by a known key) in DynamoDB.
- The production ledger runs at the same size all day. It is a provisioned Aurora cluster, so its bill is mostly instance hours. That steady branch will end in a commitment, but Sana makes it last.
- The ledger's I/O charges are a large share of its bill. Sana checks the I/O share of the bill in AWS Cost Explorer, the AWS tool that breaks down past spend. She compares both configurations' prices, then moves the cluster to Aurora I/O-Optimized, which has no per-request I/O charge.
- The development database sits idle most of the day. Sana moves it to Aurora Serverless v2, where capacity follows the load between a minimum and maximum she sets. Capacity is counted in ACUs (Aurora Capacity Units).
- She sets the minimum to 0 ACUs. The idle database now pauses on its own and resumes when a developer connects. Its storage is still billed while it sleeps.
- Login sessions follow users, so their traffic is hard to forecast. Sana keeps that table on DynamoDB on-demand capacity, which bills each request. A session is useless after it ends, so she adds TTL: each item stores its expiry as a number in epoch seconds (seconds since 1 January 1970).
- Audit events must be kept for years but are rarely read. Storage is most of that table's cost, so Sana moves it to the Standard-IA table class. Storage gets cheaper, and each read or write costs a little more.
- Every customer's dashboard asks for the same monthly totals. Sana puts Amazon ElastiCache, an in-memory cache, in front of the ledger. Repeats are answered from memory, so the cluster needs fewer readers.
- The ledger keeps 35 days of automated backups, but recovery needs only a week. Backup storage beyond the free allowance is billed. Sana lowers retention to what the recovery requirement names.
- Only now does she commit. Storage, I/O and repeated reads have been trimmed, so the remaining floor is real. Sana covers that floor with a Database Savings Plan, because Orchard Ledger may change its database mix.
Each charge went to the lever that owns it. A commitment bought at step 2 would have included waste that steps 3, 4, 5 and 8 later removed.
The rules the exam tests
- Commit to the floor, not the peak. Anything you commit to and don't use is still paid for.
- Pay per use when load is unpredictable. You accept a higher unit price in exchange for paying nothing extra when the load is absent.
- A steady relational workload is mostly instance hours. Commit to those hours with reserved DB instances or a Database Savings Plan.
- A key-value table full of old records is mostly storage. Move it to Standard-IA, and expire the items you no longer need.
- Steady DynamoDB traffic suits provisioned capacity with auto scaling. Auto scaling raises and lowers the provisioned capacity to follow the traffic.
- Heavy repeated reads are mostly read I/O. A cache in front cuts the work the database does.
- Backup storage beyond the free allowance is billed. Keep only the retention the requirement names.
- Measure before you commit. Watch the steady baseline over a representative period first, because a reservation is paid for whether or not you use it.
- A Compute Savings Plan never discounts a database. It covers EC2, Fargate and Lambda usage only.
Deep diveAurora I/O-Optimized: the numbers and the switching rules
AWS says I/O-Optimized can save up to 40 percent for clusters whose I/O spend exceeds 25 percent of the Aurora bill.
I/O-Optimized also changes the instance and storage rates. A cluster with a small I/O bill can pay more overall, so compare both bills before you switch.
The storage configuration is a cluster setting, not an instance setting. You can switch from Standard to I/O-Optimized once every 30 days, and switch back to Standard at any time.
Deep diveDynamoDB TTL and Standard-IA in detail
TTL reads an attribute that holds a Number in epoch seconds, counted from the Unix epoch. A string value, or a date written as text, never expires, so the storage keeps growing.
TTL deletes expired items at no write cost. It runs as a background process and typically deletes them within a few days. Until then, expired items can still appear in reads, so filter them out of queries.
Standard-IA cuts storage cost by about 60 percent, while reads and writes cost about 25 percent more. It pays off when storage is about 50 percent or more of the table's cost.
Standard-IA is a table class, not a separate kind of table. You can choose it when you create a table or move an existing table to it later.
Which commitment, and for how long
Step 10 is where most exam questions about commitments land. Each commitment covers a different set of services and allows a different amount of change:
- Database Savings Plan: the most flexible, with a one-year term. You commit to a fixed hourly spend, and it can cut costs by up to 35 percent. It covers Aurora, RDS, DynamoDB, ElastiCache and other database usage, and it reserves no capacity, so it suits a database mix that may change.
- Reserved DB instances: a one-year or three-year term. The discount is tied to one instance family (size-flexible), one engine and one Region.
- DynamoDB reserved capacity: saves up to 54 percent on a one-year term or 77 percent on a three-year term, in select Regions. It applies only to provisioned tables on the Standard table class.
- ElastiCache reserved nodes: a discounted rate on nodes you pay for in advance, for a one-year or three-year term. The discount is size-flexible within one node family and Region.
Term length is a bet on the floor. A three-year term locks in the instance family, engine or table design for longer. Choose it only when those are settled.
Decision guide
| If the question says… | Reach for… | Because… |
|---|---|---|
| relational database runs 24/7 at a steady size, and the family or engine is fixed for a year or more | Reserved DB instances, or a Database Savings Plan if the mix may change | Reserved DB instances fit one engine and instance family. A Database Savings Plan follows spend. |
| a development or test database is idle most of the day, with occasional spikes | Aurora Serverless v2 with a low minimum capacity, and auto-pause at 0 ACUs | Capacity follows load between your minimum and maximum. At 0 ACUs the cluster can pause. |
| a steady production Aurora cluster whose I/O charges are a large share of the bill | Aurora I/O-Optimized | No per-request I/O charges. Compare both bills first, because instance and storage rates differ. |
| a steady Aurora cluster with modest I/O and a small bill from read and write requests | Aurora Standard | Its lower instance and storage rates win when I/O is a small share of spend. |
| a DynamoDB table with unpredictable or new traffic and no forecast | DynamoDB on-demand capacity mode | Pays per request, so no unused capacity. Costs more per request than well-used provisioned. |
| a DynamoDB table with predictable traffic and a stable baseline | Provisioned capacity with auto scaling, plus reserved capacity for the baseline | Provisioned units are cheaper at steady use. Reserved capacity lowers the rate on the floor. |
| a DynamoDB table whose storage is about half its cost or more, and rarely read | Standard-IA table class | Storage about 60% cheaper, requests about 25% pricier. Reserved capacity is not supported on it. |
| session or log items that are useless after a fixed time | DynamoDB time to live on an epoch-seconds number attribute | Expired items are deleted at no write cost. Deletion can lag, so filter them out of reads. |
| the same read results requested again and again from a relational or DynamoDB backend | ElastiCache in front of the database | Fewer reads reach the database, so it can be smaller. Caching repeats beats buying capacity. |
| a cache cluster must run for years at a steady size | ElastiCache reserved nodes, with Valkey as the engine | Reserved nodes are discounted. Valkey nodes cost less than equivalent Redis OSS (open-source Redis) nodes. |
| backups kept for years for compliance, while the database is small | Lower automated backup retention, and move long-term copies to a cheaper store | Backup storage beyond the free allowance is billed. Keep only the retention the requirement names. |
| a warehouse that runs queries in bursts, with unpredictable hours | Amazon Redshift Serverless with a usage limit | Billed per RPU (Redshift Processing Unit) hour while queries run. A usage limit can alert you or stop queries. |
| a commercial database engine license is the largest line in the bill | Migrate to Aurora PostgreSQL or Aurora MySQL with AWS DMS (Database Migration Service) | Open-source-compatible engines carry no license fee. DMS moves data, and schema conversion is separate. |
Terms in this table:
- Redshift Serverless bills in RPUs for the time queries run. A steady warehouse is better on a provisioned cluster.
- AWS DMS moves the data. DMS Schema Conversion or AWS SCT (Schema Conversion Tool) converts the schema as a separate step.
- Valkey is an engine ElastiCache offers alongside Redis OSS, compatible with Redis OSS commands.
Correct pattern
REFERENCE PATTERN: a production Aurora cluster with a committed baseline and a cache for hot reads, plus two DynamoDB tables. One expires its own rows, and the other uses the cheaper storage class.
# Aurora cluster on the I/O-Optimized configuration (switch only after comparing both bills)
aws rds modify-db-cluster \
--db-cluster-identifier orders-prod \
--storage-type aurora-iopt1 \
--apply-immediately
# DynamoDB session table: expire rows by epoch time so no scheduled job is needed
aws dynamodb create-table \
--table-name sessions \
--attribute-definitions AttributeName=session_id,AttributeType=S \
--key-schema AttributeName=session_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
aws dynamodb update-time-to-live \
--table-name sessions \
--time-to-live-specification "Enabled=true,AttributeName=expires_at"
# Audit table: written all day, read rarely after its first month, so store it in Standard-IA
aws dynamodb create-table \
--table-name audit-events \
--attribute-definitions AttributeName=event_id,AttributeType=S \
--key-schema AttributeName=event_id,KeyType=HASH \
--billing-mode PAY_PER_REQUEST \
--table-class STANDARD_INFREQUENT_ACCESS
Why it holds up:
- The storage configuration is set on the cluster, not per instance. Check the I/O share of the bill in Cost Explorer, then compare both configurations' prices before you switch. If I/O turns out to be small, the same comparison tells you to switch back.
- The fixed baseline is what the commitment covers. Use a Database Savings Plan or reserved DB instances. Commit only after storage and I/O have been reduced, so the commitment is not sized to waste.
- The session table uses on-demand capacity because session traffic follows users. Its
expires_atattribute is an epoch number, so DynamoDB removes old sessions without a scheduled job. - The audit table picks Standard-IA at creation. An existing table could also move to the class later. Sessions stay on the Standard class because their reads and writes are frequent.
Traps
| The trap | Why it fails | Correct pattern |
|---|---|---|
| Switch every Aurora cluster to I/O-Optimized because it removes I/O charges | Instance and storage rates change too. A cluster with a small I/O bill can pay more overall. | Check the I/O share in Cost Explorer, compare both prices, and switch only where I/O is a large share of spend |
| Put a DynamoDB table on provisioned capacity sized to its peak to avoid throttling (rejected requests) | You pay peak capacity around the clock, including the idle part of the day. | Provisioned with auto scaling for predictable load, or on-demand for unpredictable load |
| Move a rarely read table to Standard-IA without checking its read and write volume | Storage drops about 60 percent, but requests cost about 25 percent more. Busy tables lose. | Choose Standard-IA when storage is about 50 percent or more of table cost and access is infrequent |
| Expect TTL to delete an item at the second it expires | TTL runs in the background, typically within a few days. Expired items still appear in reads. | Filter expired items out of queries, and don't rely on TTL for anything that must disappear on time |
| Store the TTL value as a string, or as a date in text form | TTL reads an epoch-seconds number. A string never expires, so storage keeps growing. | Store the expiry as a number of seconds since the Unix epoch |
| Assume Aurora Serverless v2 is always cheaper than provisioned instances | It bills the capacity used each moment. Steady high load costs more than committed instances. | Serverless v2 for idle or spiky load; provisioned with a commitment for steady load |
| Buy a 3-year Reserved DB instance for a database that will move to another engine or instance family | The discount matches one engine and instance family in a Region. A change leaves the commitment unused. | Use a Database Savings Plan when the database mix may change, and commit only after the instance size is settled |
| Believe a cache lowers cost for every read | Only repeated reads benefit. Unique queries still reach the database, and the cache costs too. | Cache the repeated reads, and size the database for the misses |
| Keep 35 days of automated backups on a database that only needs a week for recovery | Backup storage beyond the free allowance is billed every day you keep it. | Set retention to the recovery requirement, and check the free allowance before adding long-term copies |
| Use Multi-AZ as a cost-free way to get a backup | The standby is a running, billed replica. It covers an Availability Zone (AZ) failure, not deleted data. | Multi-AZ for availability (see task 2.2), snapshots and backup retention for recovery (see task 1.3) |
| Assume a Compute Savings Plan discounts a database | Compute Savings Plans cover EC2, Fargate and Lambda only. | Database Savings Plans for Aurora, RDS, DynamoDB and ElastiCache spend; Compute Savings Plans for compute spend |
Two details behind the table:
- Reserved DB instances don't reserve capacity. They only discount a matching engine and instance family, so a change of either leaves the commitment paid but unused.
- A Multi-AZ standby is a second copy in another Availability Zone (AZ), billed for its instance and storage.
Compare
| Aspect | DynamoDB on-demand | DynamoDB provisioned with auto scaling | Aurora Serverless v2 | Provisioned Aurora or RDS |
|---|---|---|---|---|
| You pay for | Each read and write request | Provisioned read and write units per hour | Aurora Capacity Units (ACUs) used, per second | Instance hours and allocated storage |
| Best load shape | Unpredictable or new | Steady, forecastable | Idle or spiky, with long quiet periods | Steady and high |
| Cheapest commitment | No reserved capacity; switch a steady baseline to provisioned | Reserved capacity for the floor | Database Savings Plan for the floor | Reserved DB instances or a Database Savings Plan |
| Idle cost | Near zero for requests | Paid for units you provisioned | Near zero at 0 ACUs with auto-pause | Full instance rate |
| Main cost risk | High per-request cost at scale | Paying for unused units | Long periods at high ACUs cost more than provisioned | Paying for capacity that goes unused |
Storage and backup costs differ by service. The exam asks which free allowance or storage class applies:
| Item | Amazon RDS | Amazon Aurora | Amazon DynamoDB |
|---|---|---|---|
| Free backup storage allowance | Equal to 100 percent of provisioned database storage, per Region per account | Equal to the latest cluster volume size for automated backup usage | Billed monthly for backup storage, prorated if a backup is removed mid-month |
| Storage that grows automatically | Storage autoscaling raises allocated storage automatically | Cluster volume grows with the data, billed for what is used | Storage is billed for what the table holds |
| Storage cost lever | gp3 for most workloads; pay for io2 only when you need its provisioned IOPS | I/O-Optimized for I/O-heavy workloads | Standard-IA table class for infrequently read data |
| Expire old data | Lifecycle is yours: delete snapshots by retention | Same as RDS for snapshots | TTL on an epoch-seconds attribute |
In the RDS column, gp3 and io2 are RDS storage types, and IOPS means input/output operations per second (the disk reads and writes storage can handle).
Worked exam scenario
Exam scenario
A subscription company keeps customer sessions in one Amazon DynamoDB table and audit activity events in a second DynamoDB table. Traffic to both tables is steady during business hours and drops to near zero overnight. Session records are needed for 24 hours, and the application already writes an expires_at attribute with each session's expiry time in epoch seconds. Activity events must be kept for 3 years for audit, but they are rarely read after their first month. The company wants the LOWEST cost and no change to the application code. What should a solutions architect do?
- A.Keep both tables on provisioned capacity sized to the business-hours peak, and keep all records with no expiry.
- B.On the sessions table, enable TTL on the expires_at attribute and use on-demand capacity. Move the activity table to the Standard-IA table class.
- C.Move both tables to the Standard-IA table class on provisioned capacity sized to the peak.
- D.Replace both tables with an Amazon RDS instance that runs 24 hours a day and delete old rows with a nightly script.
Show the walkthrough
- Underline the requirements. Session data expires after 24 hours. Activity data is kept 3 years and rarely read. Traffic follows business hours, and the goal is LOWEST cost with no code change.
- Split the data by lifetime and access. Sessions have a fixed lifetime, and the application already writes their expiry in epoch seconds. TTL on that attribute removes them without a job or a code change. Activity events are storage-heavy and rarely read, which is the Standard-IA case.
- Match the capacity to the load. Traffic drops to near zero overnight, so on-demand is the right billing mode for the sessions. Provisioned capacity sized to the peak would pay for idle hours.
- Eliminate A. Peak-sized provisioned capacity pays for idle capacity every night. Keeping sessions with no expiry grows storage forever.
- Eliminate C. Standard-IA raises the price of the reads and writes that session data gets all day. Peak-sized provisioned capacity repeats the idle-capacity error.
- Eliminate D. An RDS instance running 24 hours a day pays for idle hours. A nightly delete script is a code and operations change the stem rules out.
- Land on B. TTL removes expired sessions at no write cost, on its own schedule. On-demand matches the overnight drop, and the audit table moves to Standard-IA, where storage is the cost and reads are rare.
Answer: B
Check your understanding
Build it
Build a DynamoDB table with an expiry attribute and switch it between capacity modes. Then watch an expired item stay visible until DynamoDB removes it, in the cost-optimized databases lab.
Key takeaways
- Commit to the steady floor, let on-demand or Serverless v2 carry the unpredictable part, and never size a commitment to the peak.
- Aurora I/O-Optimized removes per-request I/O charges but changes the instance and storage rates. Choose it only when I/O is a large share of the bill.
- DynamoDB on-demand suits unpredictable traffic, and provisioned with auto scaling suits steady traffic. Standard-IA suits rarely read tables where storage is about half the cost or more.
- TTL removes expired items at no write cost, but on its own schedule. Store the expiry as an epoch number and filter expired items out of reads.
- Cache repeated reads so the database can stay smaller, and remember that a cache only helps the reads that repeat.
- Price the database by load shape and data lifetime: commit to the steady baseline, let on-demand or Serverless v2 carry the unpredictable part, expire unneeded data, and cache repeated reads.
Hands-on lab: Expire Data with TTL and Switch Capacity Modes
Sources
- https://docs.aws.amazon.com/rds/latest/auroraextendedcontent/aurora-faq-billing.html
- https://docs.aws.amazon.com/rds/latest/auroraextendedcontent/aurora-features-cost-effective.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithReservedDBInstances.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/capacity-reservations.pricing-billing.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless-v2-auto-pause.html
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Storage.html
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.Autoscaling.html
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-storage-backup.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.CreateInstance.html
- https://docs.aws.amazon.com/aws-backup/latest/devguide/rds-backup.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-understanding-billing.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/backup-restore-billing.html
- https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-workgroup-max-rpu.html
- https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-billing-on-demand.html
- https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html
- https://docs.aws.amazon.com/dms/latest/userguide/CHAP_SchemaConversion.html
- https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZSingleStandby.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CostOptimization_TableCapacityMode.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-switching-capacity-modes.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CostOptimization_TableClass.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/TTL.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/data-modeling-blocks.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CostOptimization_TableUsagePatterns.html
- https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/CacheNodes.Reserved.html
- https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-billing-on-demand.html
- https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-billing-reserved.html
- https://docs.aws.amazon.com/savingsplans/latest/userguide/plan-types.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/capacity-reservations.getting-started.html
- https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/reserved-capacity.html
- https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.Overview.StorageReliability.html
- https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/ecommerce-caching-valkey.html
- https://docs.aws.amazon.com/cost-management/latest/userguide/ce-chart.html
Last reviewed