Explain Partition Key vs Sort Key.
A partition key determines which partition stores data, while a sort key defines the order of items within that partition.
When to Use
Use a partition key when you need even data distribution across servers. Add a sort key when you want multiple related items stored together and retrieved in order—like a user’s posts sorted by time.
Example
In an Orders table, CustomerID can be the partition key, grouping all orders by customer, while OrderDate can be the sort key to sort orders chronologically.
Boost your interview prep with:
- Grokking System Design Fundamentals
- Grokking the System Design Interview
- Grokking Database Fundamentals for Tech Interviews
- Mock Interviews with ex-FAANG engineers
Why Is It Important
Choosing the right partition and sort keys ensures scalability, avoids hotspots, and makes queries efficient—critical in systems like DynamoDB.
Interview Tips
In interviews, explain clearly: partition key = distribution, sort key = ordering. Use a quick example (e.g., UserID + Timestamp). Mention trade-offs and query restrictions to stand out.
Trade-offs
Partition keys scale data well, but without a sort key, related queries are harder. Sort keys allow grouping but can create “hot” partitions if unevenly used.
Pitfalls
Common mistakes include picking a partition key that causes uneven distribution or assuming you can query solely by sort key—DynamoDB requires the partition key.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78