ScalingAdvanced
How do you choose a shard key?
“What makes a good shard key, and what is a hot shard?”
What this tests
- Shard key design
- Hot shards
- Cross-shard cost
Answers by level
Read the beginner answer first and notice what is missing.
A good shard key is one almost every query already knows, so queries stay on one shard. Hash sharding spreads load evenly regardless of distribution but scatters range queries; range sharding keeps ranges local but skews with the data; tenant sharding keeps B2B queries shard-local until a whale tenant outgrows a shard.
A hot shard is a key whose distribution concentrates traffic on one node — a monotonic id lands every insert on the last shard. Adding shards does not help because the key is the problem.
Green flags · Red flags
Strong green flag · Explains why a monotonic key creates a hot shard.
Green flags
- Key that every query knows
- Hot-shard awareness
- Cross-shard cost
Red flags
- "Shard by id" without noticing the insert hot spot
- Ignores cross-shard queries
Follow-up questions
F1
Why is a monotonically increasing id a poor shard key?
Scenario
A SaaS shards by tenant_id and one node is at 100% while others idle. What happened and what would you do?