DynamoDB Partition Keys, Sort Keys and Hot Partitions Explained
After modeling, traffic can still crush one partition. Lagos fintech lead Chioma Adeyemi saw ProvisionedThroughputExceeded on USER#celebrity during a sale. This chapter covers partition/sort keys, hot partitions, write sharding and CloudWatch clues. Modeling chapter: Data modeling.
What you'll learn in this chapter
- Explain the core idea with an everyday story
- Apply Why / What / How on the topic
- Read commands with sample output and meaning
- Map the idea across industries
- Complete the lab and cleanup
1. Everyday example: one busy lift in a tower
A tower with 40 flats but only one working lift is a hot partition. Spreading people across lifts is write sharding (USER#id#0..N). Sort keys are the floor buttons — they order stops inside one lift shaft (partition).
2. Vertical steps
3. Why do we need this?
Why do we need this?
One popular key absorbs too many reads/writes. DynamoDB partitions have throughput limits. Hot keys cause throttling even when the table has spare capacity overall.
4. What is it?
What is it?
Partition key places items; sort key orders inside the partition. Hot partition = one key overloaded. Fixes: more specific keys, write sharding suffixes, cache, or GSI fan-out for reads.
5. How to do it (step by step)
How to do it (step by step)
- Estimate peak ops/sec per PK.
- Avoid low-cardinality PKs (status=NEW alone).
- Add shard suffixes for extreme writers.
- Use CloudWatch ThrottledRequests + Contributor Insights.
- Re-test after sales/events.
6. Write sharding pattern
PK=USER#u9#0 .. USER#u9#7 for writes; compute shard = hash(requestId)%8. Reads either scatter-gather or use a materialized latest profile item.
7. CloudWatch clues
ThrottledRequests, ReadThrottleEvents, WriteThrottleEvents, SuccessfulRequestLatency. Contributor Insights lists top keys.
8. Commands with output and meaning
aws dynamodb describe-table --table-name lab-dda-shop --query 'Table.KeySchema'
# Output: HASH PK, RANGE SK — confirms key roles
aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB --metric-name ThrottledRequests \
--dimensions Name=TableName,Value=lab-dda-shop --start-time 2026-10-31T00:00:00Z --end-time 2026-10-31T23:59:59Z \
--period 3600 --statistics Sum --region ap-south-1
# Output: datapoints Sum>0 means throttling happened. Meaning: investigate hot keys, not only table capacity.
KeySchema shows HASH/RANGE roles. ThrottledRequests>0 means some partition was hot — raise shard count or redesign PK.
9. Industry stories
- Gaming (Carlos Rivera, Mexico City): shard score writes GAME#id#0..15.
- IoT (Mei Lin, Shenzhen): device#day PK spreads days.
- Retail flash sale (Rohit Sharma, Mumbai): product PK too hot — shard + DAX later.
- Social (Elena Petrova, Warsaw): celebrity feed PK sharded.
- Ads (Kenji Watanabe, Osaka): campaign#geo shards.
10. Lab
How to do it (step by step)
- Create table; hammer one PK with a loop of puts; watch ThrottledRequests.
- Add shard suffix; retry; compare throttles.
- Delete lab table.
Cleanup (stop billing)
- Delete lab tables, indexes, and triggers you created.
- Confirm with describe-table that names are gone.
11. Access-pattern workshop (paper first)
- List every screen or API that reads or writes data.
- For each: write the exact key lookup or query shape in plain English.
- Mark 1:1, 1:many, many:many relationships.
- Circle anything that needs a sort range (time, status, score).
- Only then invent PK/SK and optional GSI keys.
- Estimate peak items per partition key per second.
- Write one sample item JSON for each entity type.
- Peer-review with someone who did not design it.
12. Copy-paste DynamoDB CLI starters
# Region habit for this series
export AWS_DEFAULT_REGION=ap-south-1
# Describe + sample
aws dynamodb describe-table --table-name ShopApp
aws dynamodb scan --table-name ShopApp --max-items 3
# Query by PK (replace names)
aws dynamodb query --table-name ShopApp --key-condition-expression "PK = :pk" --expression-attribute-values '{":pk":{"S":"USER#u123"}}'
# On-demand capacity mode check
aws dynamodb describe-table --table-name ShopApp --query 'Table.BillingModeSummary'
# Streams status
aws dynamodb describe-table --table-name ShopApp --query 'Table.StreamSpecification'
13. More industry stories
- Retail (Aisha Khan, Dubai): single-table cart+orders; PK=USER#id keeps each shopper hot path local.
- Gaming (Carlos Rivera, Mexico City): leaderboard uses sparse GSI on score; write shard on hot gameId.
- IoT (Mei Lin, Shenzhen): sensor#day PK + timestamp SK; TTL 30 days keeps storage flat.
- Healthcare (Rohan Deshmukh, Pune): appointment slots use conditional Put — no double book.
- Fintech (Elena Petrova, Warsaw): Streams fan-out to audit table; never update audit in place.
- Travel (Omar Haddad, Amman): global tables for read-local catalog; writes region-sticky for inventory.
14. Glossary (short)
| Term | Meaning |
|---|---|
| PK / Partition key | Hash key that places the item in a partition |
| SK / Sort key | Orders items inside a partition; enables ranges |
| Item collection | All items that share the same PK |
| GSI | Global Secondary Index — alternate PK/SK, own partitions |
| LSI | Local Secondary Index — same PK, different SK |
| RCU / WCU | Read/Write Capacity Units on provisioned mode |
| Conditional write | Write succeeds only if a condition is true |
| Stream view type | KEYS_ONLY / NEW_IMAGE / OLD_IMAGE / NEW_AND_OLD_IMAGES |
15. Practice: explain out loud
- 60s: why access patterns come before table design.
- 60s: hot partition and one fix (write sharding).
- 60s: GSI vs LSI in one breath.
- 60s: on-demand vs provisioned for a startup.
- 60s: optimistic locking with a version attribute.
- 60s: Streams + Lambda for an audit trail.
- Record once; cut filler; record again.
16. Safe lab hygiene
- Use ap-south-1 labs with a budget alert (₹/USD).
- Prefix lab tables with lab- and your initials.
- Prefer on-demand for tiny labs unless you are learning auto scaling.
- Delete tables and Lambda triggers after the lab.
- Never point Streams consumers at production without a DLQ.
- Tag every resource Owner + Expiry.
17. How this set links other chapters
- What Is Amazon DynamoDB? — NoSQL vs RDS, first keys.
- CRUD, Query, Scan, GSI, TTL — basics we deepen, not copy.
- AWS CLI DynamoDB — command catalog.
- AWS SDK DynamoDB — SDK + light conditionals.
- Serverless project builds that *use* DynamoDB — we link, not rebuild.
18. Single-table sketch pad
Write entities as rows in one mental table before you open the console. Example for a small shop: USER#, ORD#, ORD#|ITEM#, PROD# under carefully chosen PK/SK.
| Entity | PK | SK | Example attrs |
|---|---|---|---|
| User | USER#u1 | PROFILE | name, city |
| Order | USER#u1 | ORD#2026-10-31#o9 | total, status |
| Order item | ORD#o9 | ITEM#sku1 | qty, price |
| Product | PROD#sku1 | META | title, stock |
19. Ten oral drill questions
- What is an access pattern?
- Why overload PK with entity prefixes?
- Name one hot-partition symptom.
- Sparse GSI means what?
- When is LSI impossible after create?
- On-demand bills for what?
- What does attribute_not_exists do?
- NEW_AND_OLD_IMAGES costs more — why still pick it?
- How do you stop a poison Streams message loop?
- Which existing chapter do you open for PutItem syntax?
20. Capacity and throttle drill
- Open CloudWatch for your table: ConsumedReadCapacityUnits, ConsumedWriteCapacityUnits, ThrottledRequests.
- Note whether BillingMode is PAY_PER_REQUEST or PROVISIONED.
- If provisioned, write current RCU/WCU and autoscaling min/max.
- Name your hottest expected PK in one sentence.
- Write one mitigation: shard, cache, or redesign.
- Set or verify a budget alert for DynamoDB.
- Check GSI list and whether each is still used.
- Confirm Streams enabled only where consumers exist.
21. Condition expression cheatsheet
# Create-once
attribute_not_exists(PK)
# Optimistic lock
version = :v
# Stock / seat
stock > :zero
#status = :free
# Combine
attribute_not_exists(PK) AND #type = :user
Meaning: conditions are the seatbelt for concurrent writers. Put them on every race-prone update. Full SDK samples stay in the SDK chapter — here we only list the expressions you will reuse.
22. Streams consumer checklist
- View type matches need (KEYS_ONLY vs NEW_AND_OLD).
- Lambda has DLQ and retry policy.
- Handler idempotent on eventID or keys.
- IteratorAge alarm before users feel lag.
- No accidental write-loop back into the same table without markers.
- Fan-out via SNS/EventBridge when >1 consumer team.
- Disable stream when lab ends.
23. Link map for this deep set (batch 1)
- Ch1 Modeling -> Ch2 Hot keys -> Ch3 GSI/LSI -> Ch4 Capacity -> Ch5 Transactions -> Ch6 Streams.
- Always link intro + CRUD + CLI + SDK instead of rewriting Put/Get.
- Projects P1-P7 come in later batches and reuse these ideas.
24. Extra oral drills
- Explain single-table to a product manager in 45 seconds.
- Draw PK/SK for a chat thread on a whiteboard.
- Name three CloudWatch metrics for DynamoDB pain.
- Say when you would refuse a new GSI request.
- Describe one transaction for seat + payment record.
- Explain why Streams are at-least-once.
- Convert a Scan-based feature request into a Query design.
- List cleanup steps after a DynamoDB lab.
25. Teacher story: the notebook that became a database
Ravindra once watched a shop keep every customer, order and payment in one paper notebook. Finding last Tuesday's unpaid bills meant flipping pages. DynamoDB single-table thinking is that notebook done carefully: one place, clear labels (PK/SK), and an index tab (GSI) only when a second way to find rows is worth the cost. Do not photocopy the notebook into ten unrelated books unless the shop truly has ten separate businesses.
When Meera (clinic), Omar (travel), and Aisha (retail) design together, they still start on paper: screen list, key sketch, sample JSON, peer review. Console clicks come last. That ritual is why this deep series links the intro and CRUD chapters instead of rewriting PutItem on every page.
26. Sixteen mini tasks (self-check, leak-free)
- Write three access patterns for a cart app in one minute.
- Invent PK/SK for user profile and orders under that user.
- Name one hot-partition anti-pattern.
- Explain write sharding to a teammate in 40 seconds.
- Say GSI vs LSI without notes.
- Pick KEYS_ONLY or ALL for a sparse open-orders index — why?
- Choose on-demand or provisioned for a weekend flash sale.
- List five DynamoDB bill line-item types.
- Write a create-once condition in words.
- Describe optimistic locking with a version attribute.
- When do you wrap two writes in a transaction?
- Pick a stream view type for an audit log — justify.
- Name two Stream consumer safety rules.
- What CloudWatch metric shows stream lag?
- Which linked chapter has PutItem CLI syntax?
- Write your lab cleanup checklist (table, stream, lambda, alarms).
27. Marathi classroom lines (say out loud)
- Access patterns आधी, keys नंतर — हे mantra आठवा.
- Hot partition म्हणजे एक PK वर गर्दी — shard किंवा redesign.
- GSI लवचिक; LSI create-time — चुकीचा index महाग.
- On-demand म्हणजे वापरल्यावर पैसे; provisioned म्हणजे आरक्षित units.
- Condition आणि transaction म्हणजे race साठी seatbelt.
- Streams at-least-once आहे — handler idempotent ठेवा.
28. Hindi bridge lines
- Pehle access patterns likho, baad mein PK/SK.
- Hot partition ek key par zyada load.
- GSI kabhi bhi; LSI table banate waqt.
- On-demand spike ke liye; provisioned steady ke liye.
- Transaction = sab milkar ya kuch nahi.
- Streams duplicate de sakte hain — idempotent likho.
29. Common errors and fixes
Each row is a real mistake students and juniors hit. Read the fix before you panic.
| Error / symptom | Fix |
|---|---|
| PK = status only | Include id/tenant. |
| Ignoring throttle alarms | Page on ThrottledRequests. |
| Shard count = 1 forever | Revisit after load tests. |
| Caching forgotten | Cache hot reads. |
| GSI with same hot PK | GSI can be hot too. |
| Huge items on hot PK | Keep items small. |
| No Contributor Insights | Enable for top keys. |
| Blaming on-demand mode only | Mode != hot-key fix. |
| Skipping load test before sale | Load-test celebrities. |
30. Troubleshooting checklist
- Throttles but unused capacity: hot key.
- Only one user fails: their PK.
- After sharding, reads miss: query all shards or keep read model.
- GSI throttles: check GSI PK design.
- Spike at UTC midnight: time-based PK skew.
31. FAQ
Q. Should I always use a single table?
Often yes for related access patterns; not a religion. Separate tables are fine for unrelated domains or different capacity/security needs.
Q. Do I still need RDS?
Yes for heavy joins, multi-row SQL reports, and strong relational constraints. See the intro DynamoDB vs RDS chapter.
Q. Is Scan evil?
Scan is a tool for rare admin jobs and small tables. Design so hot paths use Query/GetItem.
Q. Where are Put/Get command details?
In the CRUD survey, CLI and SDK chapters — this deep set links them instead of copying.
Q. What is a hot partition?
One PK gets disproportionate traffic.
Q. Write sharding?
Append shard ids to PK and spread writes.
Q. Does on-demand remove hot keys?
No — still partition limits.
Q. Sort key role?
Order/range inside partition.
32. Interview Q&A
Q. (B) PK vs SK?
PK places partition; SK orders inside.
Q. (B) Hot partition symptom?
Throttles on one key.
Q. (M) Write sharding how?
PK#shardN; random/hash choose shard.
Q. (M) Low cardinality risk?
Few PK values = few partitions.
Q. (S/MNC) Celebrity user design?
Shard writes; cache profile; isolate feed.
Q. (MNC) Prove fix?
Before/after ThrottledRequests + latency.
33. Tips in English, Marathi and Hindi
Ravindra Bagale's Tip (EN)
Measure per-key traffic before adding capacity.
Ravindra Bagale's Tip (MR)
Capacity आधी per-key मोजा.
Tip (HI)
पहले per-key traffic नापें।
Try at home
- List top 5 busiest keys in your app.
- Sketch a shard plan for one of them.
- Read modeling chapter once more.
In short
- PK places; SK orders.
- Hot key != table out of capacity.
- Shard, cache, redesign.
- Watch ThrottledRequests.
Revision, interview and comparison cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.








More cards: Ravi Sir's Cards.
Practice Tasks
Vidarbha Cotton Mills is a textiles business in Nagpur. Ganesh Wankhede looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 16
Easy Hot partition = uneven traffic — 1
Why: Def.
What to do: Enter 1 if a hot partition gets disproportionate traffic.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Write sharding spreads writes — 1
Why: Fix.
What to do: Enter 1 if write sharding spreads writes across suffixes.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy SK for ranges — 1
Why: Range.
What to do: Enter 1 if sort keys support range queries in a partition.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Low-cardinality PK is risky — 1
Why: Anti.
What to do: Enter 1 if a low-cardinality PK like STATUS=ACTIVE can go hot.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Easy Describe a DynamoDB table
Why: CLI.
What to do: Describe table ShopApp
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Easy Hot key YAML note
Why: Note.
What to do: YAML: symptom: throttle, fix: write-sharding.
- Start from the top-level keys the task names.
- Indent child keys with 2 spaces (no tabs).
- Fill in each property with the value from the task.
- Click Check answer. Key order does not matter.
Easy PK places the item in a partition — 1
Why: Def.
What to do: Enter 1 if the partition key places the item in a partition.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium ThrottledRequests is a clue — 1
Why: CW.
What to do: Enter 1 if ThrottledRequests helps spot capacity/hot issues.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Sparse attr for sparse GSI — 1
Why: Sparse.
What to do: Enter 1 if sparse keys/attrs exist only on some items.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Burst can hide bad design — 1
Why: Trap.
What to do: Enter 1 if burst capacity can hide a bad key design briefly.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium device#day is a common IoT PK — 1
Why: Pattern.
What to do: Enter 1 if deviceId#day style PKs help IoT time-series.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Medium Scan max 3 items
Why: CLI.
What to do: Scan ShopApp returning at most 3 items
- Read the task and decide which AWS service it is about.
- Write aws, then the service name, then the operation (the action word).
- Add each needed flag (--name) followed by its value from the task.
- Flags can be in any order. Click Check answer.
Hard Contributor Insights shows hot keys — 1
Why: Tool.
What to do: Enter 1 if Contributor Insights helps find hottest keys.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Sharded reads may need fan-in — 1
Why: Read.
What to do: Enter 1 if after write sharding you may fan-in on read or use a GSI.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Watch ConsumedWriteCapacityUnits — 1
Why: Metric.
What to do: Enter 1 if ConsumedWriteCapacityUnits is a core write metric.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.
Hard Mitigate with shard/cache/redesign — 1
Why: Options.
What to do: Enter 1 if mitigations include shard, cache, or redesign.
- Write down the numbers the task gives you.
- Work it out step by step on paper.
- Type only the final answer in the box.
- Click Check answer.