Beginner · Networking and databases: VPC and RDS · topic 17 of 50 · 30 min
Choosing a database: DynamoDB, caches and warehouses
Explanation
Why more than one kind of database?
A relational database is a great default: tables, joins, transactions and SQL. But some jobs fit other shapes better. A shopping cart read millions of times a minute, a leaderboard that changes every second, or a report over three years of sales each strain a single relational database in different ways. Cloud providers offer purpose-built databases for each shape.
| Type | AWS | Good for |
|---|---|---|
| Relational | RDS, Aurora | Orders, payments, anything with joins and transactions |
| Key-value | DynamoDB | Sessions, carts, user profiles, IoT data at huge scale |
| Document | DocumentDB (MongoDB compatible), DynamoDB | JSON-shaped records with flexible fields |
| In-memory | ElastiCache (Valkey, Redis OSS, Memcached) | Caching, leaderboards, rate limits |
| Warehouse | Redshift | Analytics over large historical data with SQL |
DynamoDB: the key ideas
Amazon DynamoDB is a fully managed, serverless key-value and document database. There are no servers or versions to manage, and reads and writes take single-digit milliseconds at almost any scale. In exchange, you design the table around how you will query it.
- Item: one record, like a row, holding attributes. An item can be up to 400 KB.
- Partition key: the attribute DynamoDB hashes to decide where an item is stored. Every query must give one exact partition key value.
- Sort key (optional): orders items that share a partition key, and lets you ask for ranges, such as orders between two dates or keys that begin with "2026-03".
- Primary key: the partition key, or partition key plus sort key. It must be unique; writing the same key again replaces the item.
- Query reads one partition key efficiently. Scan reads the whole table and is slow and costly on big tables. Add a Global Secondary Index (GSI) when you need another access pattern.
| customer_id (partition key) | order_date (sort key) | total | status |
|---|---|---|---|
| C-1001 | 2026-03-02#O-551 | 1299 | DELIVERED |
| C-1001 | 2026-03-18#O-602 | 450 | SHIPPED |
| C-2040 | 2026-03-05#O-560 | 8999 | PLACED |
With this design, "all orders for C-1001 in March 2026, newest first" is a single fast Query. Putting the order ID after the date in the sort key keeps keys unique when a customer orders twice on the same day.
Capacity modes and consistency
On-demand mode charges per request and scales by itself, which suits new or spiky apps. Provisioned mode lets you set read and write capacity units (optionally with auto scaling) and is cheaper for steady, predictable traffic. One write capacity unit (WCU) is one write per second of up to 1 KB. One read capacity unit (RCU) is one strongly consistent read per second of up to 4 KB, or two eventually consistent reads. Eventually consistent reads (the default) may return data a moment old; strongly consistent reads always return the latest write.
Global tables replicate a table to several regions, and every region can accept writes. DynamoDB also offers TTL (automatic deletion of expired items), Streams (a change feed for triggers) and point-in-time recovery.
Caches and warehouses
Amazon ElastiCache runs Valkey, Redis OSS or Memcached in memory. The common pattern is cache-aside: the app checks the cache first; on a miss it reads the database and stores the result with a TTL (time to live). This cuts database load and response times for data that many users read, like a product page. Amazon Redshift is a columnar data warehouse: it stores each column together so queries like "total sales by state for three years" scan only the columns they need.
Equivalents on other clouds
- Azure: Azure SQL Database and Azure Database for PostgreSQL/MySQL (relational), Cosmos DB (key-value and document), Azure Managed Redis (cache), Azure Synapse Analytics and Microsoft Fabric (warehouse).
- Google Cloud: Cloud SQL, AlloyDB and Spanner (relational), Firestore and Bigtable (NoSQL), Memorystore (cache), BigQuery (warehouse).
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Choosing a database: DynamoDB, caches and warehouses · 1/7
Pick a database by how data is read and written. Relational is a good default, but not the only choice.
Prefer a video by a teacher? Find free videos on “dynamodb partition key sort key tutorial elasticache redshift when to use” on YouTube ↗
In real life: A food delivery app during IPL finals
A food delivery app stores live order status in DynamoDB with order_id as the partition key, because the app and the rider both poll it every few seconds and traffic jumps tenfold during an IPL final. Restaurant menus are cached in ElastiCache for Valkey with a 5 minute TTL. Payments and refunds live in Aurora PostgreSQL, where transactions matter. Every night order data is copied to Redshift so the business team can ask which dishes sold most in each city during the match.
aws dynamodb query \
--table-name Orders \
--key-condition-expression "customer_id = :c AND begins_with(order_date, :m)" \
--expression-attribute-values '{":c": {"S": "C-1001"}, ":m": {"S": "2026-03"}}' \
--no-scan-index-forwardPractice (0/3 done)
You need the 10 most recent orders of one customer from a DynamoDB table. Which key design makes that one Query?
Simulate a DynamoDB table with a partition key and a sort key. The table is a dict: partition key value -> dict of sort key value -> item. Write put_item(table, pk, sk, item) that stores the item (replacing any item with the same pk and sk), and query(table, pk, begins_with="", newest_first=False) that returns the items for that pk whose sort key starts with begins_with, sorted by sort key (descending if newest_first). An unknown pk returns [].
Write capacity_units(per_second, item_kb, kind) for DynamoDB provisioned mode. kind is "write", "strong" (strongly consistent read) or "eventual" (eventually consistent read). A write uses 1 WCU per 1 KB (rounded up). A strong read uses 1 RCU per 4 KB (rounded up). An eventual read costs half of a strong read; round the TOTAL up. Return the whole number of units needed.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- DNS and CDN: Route 53 and CloudFrontNetworking and databases: VPC and RDS · same module
- VPC security and connectivityNetworking and databases: VPC and RDS · same module
- Core Google Cloud servicesGoogle Cloud and comparing the clouds
- Caching and RedisBackend Development · Performance and reliability
- Denormalisation, OLTP and OLAPSQL and Databases · Schema design and normalisation
- Serverless with AWS LambdaServerless, monitoring and cost control
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the maximum size of a single DynamoDB item?
Answer: 400 KB
A DynamoDB item, including attribute names and values, can be up to 400 KB.
Which DynamoDB capacity mode suits a brand-new app with unpredictable, spiky traffic?
Answer: On-demand
On-demand scales automatically and bills per request, so you do not have to guess capacity.
A product page is read thousands of times per minute and changes rarely. What reduces database load most?
Answer: A cache in ElastiCache with a TTL
A cache serves repeated reads from memory; the TTL keeps the data reasonably fresh.
The business team wants sales totals by state across five years of data. Which service is designed for this?
Answer: Amazon Redshift
Redshift is a columnar data warehouse for large analytical SQL queries.
Which Google Cloud service is the closest match to Amazon Redshift?
Answer: BigQuery
BigQuery is Google Cloud's serverless data warehouse.
Which service runs your container, scales with traffic and can scale down to zero?Related
Answer: Cloud Run
Cloud Run is serverless containers with scale to zero.
A product's price changed in the database. What should you do with its cache key?Related
Answer: Delete it, so the next read loads the new price
Deleting (invalidating) the key after the update makes sure the next read gets fresh data.
From Caching and Redis
Why do warehouses often store data in columns rather than rows?Related
Answer: A query summing one column reads only that column from disk
Analytics touches a few columns of many rows; columnar storage reads just those columns.
What gives a Lambda function permission to read from a DynamoDB table?Related
Answer: Its execution role
The execution role is the IAM role Lambda assumes when running your code. Its policy must allow the DynamoDB read.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 1 more topic in “Networking and databases: VPC and RDS” before its exam: DNS and CDN: Route 53 and CloudFront.
- Module 4 exam: Networking and databases, VPC and RDS · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, Serverless, monitoring and cost control. 50 topics left in the course before the final exam.