Bird
0
0

How can you improve partition key distribution to avoid hot partitions?

hard🚀 Application Q15 of 15
DynamoDB - Access Patterns and Query Optimization
You have a DynamoDB table storing orders with partition key 'CustomerId'. Some customers place thousands of orders daily, others only a few. How can you improve partition key distribution to avoid hot partitions?
AUse 'OrderId' alone as partition key
BKeep 'CustomerId' as partition key and add 'OrderId' as sort key
CUse a composite key combining 'CustomerId' and 'OrderDate' as partition key
DUse a random number as partition key for all orders
Step-by-Step Solution
Solution:
  1. Step 1: Identify problem with current partition key

    Using only 'CustomerId' causes hot partitions for customers with many orders.
  2. Step 2: Improve distribution by combining keys

    Combining 'CustomerId' and 'OrderDate' creates more unique partition keys, spreading load better.
  3. Step 3: Understand why other options fail

    Keep 'CustomerId' as partition key and add 'OrderId' as sort key keeps same partition key, so hot partitions remain; Use 'OrderId' alone as partition key loses customer grouping; Use a random number as partition key for all orders breaks data organization.
  4. Final Answer:

    Use a composite key combining 'CustomerId' and 'OrderDate' as partition key -> Option C
  5. Quick Check:

    Composite key increases uniqueness, reduces hot partitions [OK]
Quick Trick: Combine keys to increase uniqueness and spread load [OK]
Common Mistakes:
MISTAKES
  • Adding sort key but not changing partition key
  • Using only order ID loses customer grouping
  • Random keys break data access patterns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More DynamoDB Quizzes