Amazon DynamoDB Tutorial 0/30 lessons ~6 min read Lesson 7

    Partition Key Design and Hot Partitions

    DynamoDB spreads data across physical partitions by hashing the partition key.

    Course progress0%
    Focus
    10 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    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 keyVerdictWhy
    CUSTOMER#123GoodMillions of customers, traffic spread out
    STATUS#PENDINGBadFew values; every new order writes the same key
    DATE#2026-11-19Bad for writesAll of today's writes land on one key
    DATE#2026-11-19#7 (sharded)AcceptableWrites 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:

    ts
    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 / WriteThrottleEvents and ThrottledRequests rising 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.

    3 questions
    1IntermediateQuestionWhat is a hot partition and how do you fix it?+

    Answer

    A hot partition is a partition receiving a disproportionate share of traffic, usually because one partition key value is very popular. Fixes: choose a higher-cardinality key, add write sharding with a suffix, cache hot reads (DAX or an application cache), or move the hot aggregate (for example a global counter) to a different design such as per-shard counters summed on read.
    2AdvancedQuestionDoes adaptive capacity eliminate the need for good key design?+

    Answer

    No. Adaptive capacity redistributes throughput between partitions and can split out hot items, but one key value still cannot exceed the per-partition throughput limits. A poorly distributed key will still throttle under sustained load.
    3IntermediateQuestionHow do you read data that was written with random shard suffixes?+

    Answer

    Issue one Query per shard (in parallel) and merge the results in the application. If you need direct lookups, use a deterministic suffix derived from the item id so the shard can be recomputed.

    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.

    Ready to mark this lesson complete?Track your journey across the entire course.