Why The Key Matters
When you shard a database, the sharding key decides which node holds each row. A good key spreads data and load evenly. A bad key creates a hotspot where one shard does most of the work while others sit idle.
What Makes A Good Key
- High cardinality so values spread across many shards.
- Even access so no single value dominates traffic.
- It should match the query pattern so most queries hit one shard.
Common Mistakes
- Sharding by a monotonically increasing timestamp sends all new writes to one shard.
- A low cardinality field like country crams large groups onto few shards.
- Keys that ignore queries force expensive cross shard joins and scatter gather.
Key idea
The sharding key must have high cardinality, spread load evenly, and align with query patterns, or you risk hotspots and costly cross shard operations.