Partition Key Design and Hot Partitions
DynamoDB spreads data across physical partitions by hashing the partition key.
Introduction
DynamoDB spreads data across physical partitions by hashing the partition key. Each partition can serve up to about 3,000 read capacity units and 1,000 write capacity units per second and stores roughly 10 GB. If one key receives most of the traffic, that partition throttles even though the table as a whole has spare capacity.
This lesson shows how to choose partition keys with high cardinality and even request distribution, and what to do when a natural key is hot.
Purpose of this lesson
You will learn to evaluate a candidate partition key, recognise hot-key symptoms in CloudWatch, and apply write sharding when a single logical key must absorb heavy writes.
Understanding the topic
What makes a good partition key:
- High cardinality — many distinct values (
CUSTOMER#<id>,ORDER#<id>), not a handful (status,country). - Even request distribution — traffic is spread across values, not concentrated on today's date or one celebrity user.
- Matches the access pattern — you know the key value at read time, so you can use GetItem or Query.
- Adaptive capacity automatically shifts throughput toward busy partitions and can isolate a very hot item, but it cannot exceed per-partition limits for a single key.
- Burst capacity retains up to 300 seconds of unused throughput, which hides short spikes — not sustained hot keys.
| Candidate key | Verdict | Why |
|---|---|---|
CUSTOMER#123 | Good | Millions of customers, traffic spread out |
STATUS#PENDING | Bad | Few values; every new order writes the same key |
DATE#2026-11-19 | Bad for writes | All of today's writes land on one key |
DATE#2026-11-19#7 (sharded) | Acceptable | Writes spread over N suffixes; reads fan out N Queries |
Informative example
Write sharding a hot daily key. Events for one day are written to one of 10 shards; readers query all shards in parallel and merge:
import { PutCommand, QueryCommand } from "@aws-sdk/lib-dynamodb";import { ddb, TABLE } from "./ddb";const SHARDS = 10;export async function recordEvent(day: string, eventId: string, payload: object) {const shard = Math.floor(Math.random() * SHARDS);await ddb.send(new PutCommand({TableName: TABLE,Item: { PK: `EVENTS#${day}#${shard}`, SK: `EVENT#${eventId}`, ...payload },}));}export async function eventsForDay(day: string) {const pages = await Promise.all(Array.from({ length: SHARDS }, (_, shard) =>ddb.send(new QueryCommand({TableName: TABLE,KeyConditionExpression: "PK = :pk",ExpressionAttributeValues: { ":pk": `EVENTS#${day}#${shard}` },})),),);return pages.flatMap((p) => p.Items ?? []);}
Random suffixes give the most even spread. If you need to read one specific item later, derive the shard from a hash of the item id instead (hash(eventId) % SHARDS) so you can compute the key again without querying every shard.
Monitoring strategy
Hot keys show up as throttling while consumed capacity for the whole table stays low. Watch these signals:
ReadThrottleEvents/WriteThrottleEventsandThrottledRequestsrising while table-level consumption is below provisioned or on-demand limits.- CloudWatch Contributor Insights for DynamoDB lists the most-accessed and most-throttled partition keys.
- SDK retries (
ProvisionedThroughputExceededException,ThrottlingException) in application logs and increased p99 latency.
Best practices
- Prefix keys with the entity type (
CUSTOMER#,ORDER#) so values stay unique across entity types in one table. - Use natural high-cardinality identifiers (customer id, order id, device id) as the partition key.
- Shard only when you have measured a hot key; sharding makes every read fan out.
- Enable Contributor Insights on tables with uneven or unknown traffic.
Common mistakes
- Using a low-cardinality attribute such as status, type, or country as the partition key.
- Using a timestamp or date as the partition key for write-heavy data.
- Assuming on-demand mode removes hot-partition limits — per-partition limits still apply.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhat is a hot partition and how do you fix it?+
Answer
2AdvancedQuestionDoes adaptive capacity eliminate the need for good key design?+
Answer
3IntermediateQuestionHow do you read data that was written with random shard suffixes?+
Answer
Hands-on exercise
Hands-on: implement recordEvent with a deterministic shard (hash(eventId) % 10, for example using the first byte of a SHA-256 digest). Write 1,000 events for one day, then call eventsForDay and confirm it returns exactly 1,000 items. Count how many items landed in each shard.
Summary
Partition keys decide how load spreads across partitions. Choose high-cardinality keys you know at read time, monitor for throttling with Contributor Insights, and shard only measured hot keys.