DynamoDB in depth
Know what DynamoDB does with each request, and you can predict what it costs, when it throttles, and which guarantees you really get.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
On Sunday, 20 September 2015, DynamoDB in AWS's US-East Region began returning errors at 2:19 a.m. Pacific time. 1
Inside DynamoDB, each table is split into partitions spread across storage servers. A server's list of partitions is its "membership". An internal metadata service keeps these lists. Servers check their list from time to time. If one cannot get it in time, it retries and stops taking requests. 1
Customers had rapidly adopted global secondary indexes (GSIs). Each GSI has its own partitions, so membership lists grew. A table with many partitions could see its share of these lists double or triple. 1 AWS later wrote: "We did not have detailed enough monitoring for this dimension (membership size)". 1
Then a short network blip made many servers ask for their lists at once. The metadata service slowed past the time limit. Servers that got no answer took themselves out of service and retried, which added more load. Even healthy servers started to fail their next renewals. 1 By 2:37 a.m., errors were far above anything seen in three years. They settled at about 55% of requests. 1
At 5:06 a.m., AWS paused requests to the metadata service. That cut the retries and took load off the service, so AWS could add capacity. By 7:10 a.m., errors were low enough for most customers to work normally. SQS, EC2 Auto Scaling, CloudWatch and the AWS Console were hit too. 1
A GSI looks like a small feature. Inside, it meant more partitions, more metadata and more work. That is why it helps to know what DynamoDB does with your table.
It happens for real
Amazon Web Services · 20 Sept 2015AWS DynamoDB outage: storage servers could not get their partition listsDynamoDB in US-East returned errors for about five hours, with errors settling at about 55% of requests, and SQS, EC2 Auto Scaling, CloudWatch and the AWS Console were hit too. All incidents tagged “retries”The idea in simple words
DynamoDB is a key-value and document database that AWS runs for you. You never see a server. You see tables, keys, indexes and a bill.
Under that, three simple rules decide almost everything:
- Every request costs capacity units, based on item size and read type.
- Every table is a set of partitions. Each partition has hard limits per second.
- Every partition is a small replica group with one leader, spread across zones.
How to choose keys is covered in Data modelling for NoSQL. This lesson is about what happens after that: cost, limits and guarantees.
The key idea. In DynamoDB, a cheap design is a correct design. Count the units each request uses, keep each partition under its limits, and read the fine print on every guarantee: indexes, transactions, TTL and global tables each have one.
How it works
The path of one request
DynamoDB is made of many services. The core ones are request routers, the metadata service and storage nodes. 2 A router authenticates each request, looks up where its key lives, and sends it on. 2
Each partition has replicas in different Availability Zones. They form a replication group that uses Multi-Paxos to elect a leader. 2 Only the leader serves writes and strongly consistent reads. 2 Step through one write. Use Next and Back, or the ← and → keys.
- Your request first reaches a request router. It checks who you are, then looks up which partition holds this key. That map comes from the metadata service and is cached.
- Each partition is a small group of replicas in different Availability Zones. The router sends the write to the group's leader.
- The leader writes a log record and sends it to its peers. The group uses Multi-Paxos to agree on a leader and on each write.
- Once a quorum, two of the three replicas, has saved the record, the write is acknowledged. One slow zone does not block it.
- A strongly consistent read must go to the leader. An eventually consistent read can go to any replica, so it can be a little behind. It also costs half as much.
A write is acknowledged once a quorum, two of the three replicas, has saved its log record. 2 Any replica can serve an eventually consistent read, so that read may miss the newest write. 2 Reads are eventually consistent by default. 5
Capacity units: the math
A read capacity unit is one strongly consistent read per second of an item up to 4 KB. An eventually consistent read costs half. 5 A write capacity unit is one write per second of an item up to 1 KB. 5
Sizes always round up. A 3,500-byte read counts as 4 KB. A 500-byte write counts as 1 KB. 3 A transactional read or write costs double. 3 An UpdateItem pays for the larger of the old and new item, even if you change one attribute. 3
Worked example: 500 strongly consistent reads per second of 6 KB items. 6 KB rounds to 8 KB, so each read costs 2 units: 1,000 units in total. Make them eventually consistent, and it drops to 500.
A Query adds up the sizes of all items it returns, then rounds once. 3 So a few small items in one Query cost far less than many separate GetItems.
On-demand or provisioned
On-demand is the default and the recommended mode. You pay per request. 4 A new on-demand table can take 4,000 writes and 12,000 reads per second. It instantly handles up to double its previous peak. Grow past double within 30 minutes, and you can be throttled. 4
Provisioned mode charges per hour for the capacity you set, used or not. 5 Auto scaling moves it toward a target utilization. AWS recommends 70%. It acts only after two minutes over target, and alarms can add a few more minutes. 5 So it follows ramps, not sudden spikes.
Hot partitions: burst, adaptive capacity, split
One partition takes at most 3,000 read units and 1,000 write units per second. 6 DynamoDB saves up to 300 seconds of unused capacity for short bursts. 6 Adaptive capacity instantly gives more of the table's capacity to a busy partition. It can also move hot items apart, even to one item per partition. 6
DynamoDB also splits a partition for consumption, at a point chosen from the keys it sees. Splits usually take minutes. A split does not help one hot item or keys accessed in sequence. 2 For those, see Scaling writes and hot keys.
GSI and LSI
A GSI has its own partitions 1 and, on a provisioned table, its own read and write capacity. 7 It is updated asynchronously, so it supports only eventually consistent reads. 7 A table write succeeds only if every affected GSI has enough write capacity. Otherwise the table write is throttled. 7 That is back-pressure from the index onto your table.
A local secondary index (LSI) keeps the table's partition key with a different sort key. You can only create it with the table, and you get up to five. 8 It allows strongly consistent reads. 8 The catch: with any LSI, one partition key value can hold at most 10 GB, table and index items together. Past that, writes that grow it can fail with ItemCollectionSizeLimitExceededException. 8 Adaptive capacity will not split such an item collection either. 6
Conditional writes and optimistic locking
One UpdateItem is atomic. The risk is read, change, write back: someone else can write in between. 9 The fix is optimistic locking: keep a version attribute, and write only if it has not changed. 9 That check is a conditional write: the condition is tested on the current item, and a false condition stops the write. 10
// ddb is a DynamoDBDocumentClient (@aws-sdk/lib-dynamodb)
try {
await ddb.send(new UpdateCommand({
TableName: "Users",
Key: { PK: "USER#42", SK: "PROFILE" },
UpdateExpression: "SET #n = :name, #v = :next",
ConditionExpression: "#v = :seen",
ExpressionAttributeNames: { "#n": "name", "#v": "version" },
ExpressionAttributeValues: { ":name": "Asha", ":seen": 7, ":next": 8 },
}));
} catch (e) {
if (e.name !== "ConditionalCheckFailedException") throw e;
// Someone wrote first. Read the item again, redo the change, retry.
}A failed condition still uses write capacity. 3 Set ReturnValuesOnConditionCheckFailure to ALL_OLD to get the current item with the error, at no read cost. 10
Transactions
TransactWriteItems changes up to 100 items, all or nothing. 11 Each item costs two writes, and a cancelled transaction still pays them. 11 Two transactions on the same item can cancel each other, so keep them small. 11 For safe retries, pass a client token. It is valid for 10 minutes. 11
TTL and Streams
With TTL, you store an expiry time in epoch seconds. DynamoDB deletes the item "typically within a few days" after it expires, at no write cost. 12 Until then, reads still return it. Filter expired items out yourself. 12
DynamoDB Streams records every item change. Each record appears once, in order for each item. 13 Records live for only 24 hours. 13 A consumer that falls a day behind loses changes. See Sagas, outbox and CDC for how to use a change feed.
Global tables
A global table keeps replicas in several Regions. The default mode, MREC, copies changes "typically within a second or less". 14 If two Regions change one item at once, the latest timestamp wins. AWS calls this "last writer wins". 14 Condition checks only see the local Region's copy, 14 so version checks do not stop conflicts across Regions. 9
The newer MRSC mode copies each write to at least one other Region before it returns. It always spans exactly three Regions: three replicas, or two replicas and a witness. 14 A clashing write fails with ReplicatedWriteConflictException, and you retry. 14 Writes are slower, and MRSC does not support TTL, LSIs or transactions. 14 Multi-region covers when each model fits.
Pages and filters
A Query returns at most 1 MB per page. If the response has LastEvaluatedKey, pass it as ExclusiveStartKey in the next call. You are done only when it is missing. 15
A filter runs after the read, so it does not lower the cost. 16 The 1 MB limit applies before the filter, so a page can come back empty and still not be the last. 15 If you throw most items away, fix the key or add an index.
Trade-offs
| Choice | Good for | Cost | Watch out for |
|---|---|---|---|
| On-demand | Yes New or spiky traffic. | Pay per request. | Throttles if traffic more than doubles within 30 minutes. 4 |
| Provisioned with auto scaling | Yes Steady, forecastable traffic. | Pay per hour, used or not. | Reacts in minutes, not seconds. 5 |
| GSI | A new access pattern, added any time. | Its own writes and storage. | Stale reads, and throttling of table writes. 7 |
| LSI | Another sort order with strong reads. | Shares the table's capacity. | Must exist at table creation. 10 GB per partition key. 8 |
| Global table, MREC | Fast local writes in many Regions. | Replicated writes in each Region. | Last writer wins can drop a write. 14 |
| Global table, MRSC | No lost writes when a Region fails. | Slower writes and strong reads. | Exactly three Regions. No TTL or transactions. 14 |
Simple rule: start with on-demand and no LSI. Add a GSI per proven access pattern. Move to provisioned only when traffic is steady and the bill matters.
At work: how a senior uses this
- Write the unit cost next to each access pattern: item size, read type, calls per second.
- Ask: "What is the peak per partition key, not per table?" 1,000 write units a second (1,000 writes of up to 1 KB) is the ceiling.
- Before you add a GSI, check its write capacity can match the table's. AWS says it should be equal or greater. 7
- Avoid an LSI unless you need strong reads on another sort key. Ask if any partition key can grow past 10 GB.
- Add a version attribute to every item that users edit, and use a condition on every write.
- Treat TTL as cleanup, not as a timer. Filter expired items in reads.
- Alarm on stream consumer lag well below 24 hours.
- Before a global table, list the items two Regions might change at once.
With AI
What to ask the agent
"Here are our access patterns with item sizes and peak rates. For each one, compute read or write capacity units per second, showing the rounding. Then name the partition key value with the highest load."
"Rewrite this read-modify-write code to use a version attribute and a ConditionExpression. Handle ConditionalCheckFailedException by reading again and retrying at most 3 times."
"Find every Query and Scan in this service that uses a FilterExpression. For each, estimate how many items it reads versus returns, and propose a key or index that avoids the filter."
What to check yourself
- Sizes are rounded up per the rules: 4 KB for reads, 1 KB for writes, and doubled for transactions.
- Pagination loops until
LastEvaluatedKeyis missing, not until a page is empty. - Code reading a GSI does not expect read-your-writes.
- No condition check is trusted across Regions in an MREC global table.
- Retries on throttling use backoff, as in Backoff, jitter and retry budgets.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 16 sources and related lessons
- Amazon Web Services, “Summary of the Amazon DynamoDB Service Disruption and Related Impacts in the US-East Region” (20 September 2015) (opens in a new tab)
How bigger partition lists from new GSIs, a short network blip and retries took DynamoDB to about 55% errors. - Mostafa Elhemali et al., “Amazon DynamoDB: A Scalable, Predictably Performant, and Fully Managed NoSQL Database Service”, USENIX ATC 2022 (opens in a new tab)
Section 3 has request routers, the metadata service and Multi-Paxos replica groups. Section 4 covers admission control, split for consumption and on-demand. - Amazon DynamoDB Developer Guide: DynamoDB read and write operations (opens in a new tab)
How each read and write is rounded up and turned into capacity units, with examples. - Amazon DynamoDB Developer Guide: DynamoDB on-demand capacity mode (opens in a new tab)
The default mode, starting limits for new tables, and the double-the-previous-peak rule. - Amazon DynamoDB Developer Guide: DynamoDB provisioned capacity mode (opens in a new tab)
Capacity units, auto scaling with a target utilization, and how fast it reacts. - Amazon DynamoDB Developer Guide: DynamoDB burst and adaptive capacity (opens in a new tab)
Five minutes of saved burst capacity, adaptive capacity, and the per-partition limits. - Amazon DynamoDB Developer Guide: Using Global Secondary Indexes in DynamoDB (opens in a new tab)
Asynchronous index updates, eventually consistent reads only, and how a short index throttles table writes. - Amazon DynamoDB Developer Guide: Local secondary indexes (opens in a new tab)
Same partition key, strongly consistent reads allowed, and the 10 GB limit per partition key value. - Amazon DynamoDB Developer Guide: Best practices for handling concurrent updates in DynamoDB (opens in a new tab)
Optimistic locking with a version attribute, transactions, and the lock client, and when to use each. - Amazon DynamoDB API Reference: UpdateItem (opens in a new tab)
ConditionExpression, ReturnValuesOnConditionCheckFailure, and the errors UpdateItem can return. - Amazon DynamoDB Developer Guide: Amazon DynamoDB Transactions: How it works (opens in a new tab)
Limits, isolation, conflicts, the client token, and what a cancelled transaction still costs. - Amazon DynamoDB Developer Guide: Using time to live (TTL) in DynamoDB (opens in a new tab)
Expiry timestamps in epoch seconds, deletes that come days later, and free deletes. - Amazon DynamoDB Developer Guide: Change data capture for DynamoDB Streams (opens in a new tab)
24-hour retention, exactly-once records, and ordering per item. - Amazon DynamoDB Developer Guide, “How DynamoDB global tables work” (opens in a new tab)
The eventual (MREC) and strong (MRSC) multi-Region modes, conflicts, and what each mode does not support. - Amazon DynamoDB Developer Guide: Paginating table query results in DynamoDB (opens in a new tab)
The 1 MB page, LastEvaluatedKey and ExclusiveStartKey, and empty pages. - Amazon DynamoDB Developer Guide: Filter expressions for the Query operation in DynamoDB (opens in a new tab)
Why a filter does not lower the read cost of a Query.
Real incident: Amazon Web Services, 20 Sept 2015: AWS DynamoDB outage: storage servers could not get their partition lists
Case studies: Amazon: What ten years of running DynamoDB taught its builders
Related: Data modelling for NoSQL · Scaling writes and hot keys · Multi-region systems and data locality · Secondary, composite and special indexes · Sharding and consistent hashing · Locking and MVCC in practice · Sagas, outbox and CDC · Cassandra in depth
- Before this: Data modelling for NoSQL and Scaling writes and hot keys.
- Related: Secondary and composite indexes, Locking and MVCC in practice, and Cassandra in depth.
- Another DynamoDB outage, from DNS automation: AWS, October 2025.