Knowledge Guide
HomeSystem DesignScalable Systems (Advanced Topics)

hard Shard Keys: many-key skew vs a single hot key

Hashing spreads keys evenly — but a single key still lands on one shard

Sharding splits data across N nodes by a shard key. Hashing that key, shard = hash(key) mod N, scatters the whole key space uniformly, so many keys land in roughly equal piles — that is what kills distributional skew and range hotspots. But the hash of a single key is a single number, so it maps to exactly one shard. Hashing therefore fixes the many-keys problem and does nothing for a single hot key: the key is the atomic unit of placement, and no hash function can put one key on two shards. These are two different problems that look alike, and only one of them is a hashing problem.

Left: 1000 keys hashed across four shards land roughly 250 each, so distributional skew is gone. Right: one celebrity key at 40,000 reads/sec hashes to shard 2 and makes it a 40k+ hotspot while the other three shards stay near 3k; the single key is atomic so it stays on one shard.
Left: 1000 keys hashed across four shards land roughly 250 each, so distributional skew is gone. Right: one celebrity key at 40,000 reads/sec hashes to shard 2 and makes it a 40k+ hotspot while the other three shards stay near 3k; the single key is atomic so it stays on one shard.

Trace it: 1000 even keys vs one celebrity

Four shards S0–S3, keys placed by hash(key) mod 4.

Case 1 — many keys, distributional skew

1000 keys, each read ~40 times/sec (40,000 reads/sec total, evenly across keys). A good hash spreads them ~250 keys per shard, so each shard serves ~10,000 reads/sec. Balanced — hashing did its job. (Had we used the raw key prefix as the shard, all user:1… keys could pile on one shard; hashing is precisely the fix for that.)

Case 2 — one hot key

Now a hot-skew workload where one celebrity key user:celeb takes 40,000/s on its own while the other 999 keys add ~3k/s per shard on top. hash("user:celeb") mod 4 = 2. Shard 2 now eats 40,000 reads/sec; S0, S1, S3 sit near-idle. Rehashing, a bigger hash, more shards — none help, because every one of them still sends this one key to exactly one shard. This is the identical mechanism behind a rate-limiter hot key (one celebrity tenant’s INCRs hammering one Redis slot): sharding distributes many keys, never one hot key.

The only things that fix a single hot key

Left: sub-bucketing splits user:celeb into eight sub-keys celeb#0..celeb#7, each hashed separately so 40k/8 = 5k per sub-key spreads across shards; reads fan out and sum the eight. Right: replication copies the key to all four shards so round-robin reads give 40k/4 = 10k each, at the cost of writes fanning out to every copy.
Left: sub-bucketing splits user:celeb into eight sub-keys celeb#0..celeb#7, each hashed separately so 40k/8 = 5k per sub-key spreads across shards; reads fan out and sum the eight. Right: replication copies the key to all four shards so round-robin reads give 40k/4 = 10k each, at the cost of writes fanning out to every copy.

Sub-bucketing — split the key into N sub-keys

Replace user:celeb with user:celeb#0 … user:celeb#7. Each sub-key hashes independently, so the 40,000/s spreads to ~5,000/s across (up to) 8 shards. A read fans out to all 8 sub-keys and combines them (sum a counter, or pick any replica for a value). Cost: every read is now an N-way fan-out and N× the storage; an exact single-key atomic operation is lost (you aggregate). This is the same sub-counter trick used to defuse rate-limiter hot keys.

Replication — copy the hot key to several shards

Keep one logical key but store R copies, one per shard, and route reads round-robin: 40,000/s ÷ 4 = 10,000/s each. Cost: every write must fan out to all R copies and they can be briefly inconsistent — so replication of a hot key suits read-heavy keys (a trending post, a config blob), not write-hot ones.

Resharding cost — why the hash scheme matters when N changes

Adding a shard exposes the second big difference between hashing schemes. With plain modulo hashing, changing mod 4 to mod 5 remaps almost every key: a key stays put only when hash mod 4 == hash mod 5, which (over one period of 20) happens for just 4 of 20 residues — so ~80% of all keys move, a data-migration storm that can saturate the cluster. Consistent hashing (with virtual nodes) instead places shards and keys on a ring; adding the 5th shard only steals the arc that now falls to it, moving about 1/5 ≈ 20% of keys. Same resharding, 4× less movement — and vnodes keep that movement even instead of dumping it all on one neighbor.

Scheme4→5 shards: keys movedWhy
hash mod N~80%changing the modulus reshuffles nearly every assignment
consistent hashing + vnodes~20% (≈ 1/(N+1))only the arc reassigned to the new node moves

Pitfalls

Judgment — two decisions, kept separate

Hash sharding vs range sharding

Hash sharding gives even load and kills hotspots for many keys, but scatters ordered data, so range queries fan out to every shard. Range sharding keeps contiguous key ranges on a shard, so range scans and “latest N” are cheap and local — but a hot range (today’s date, an auto-increment tail) concentrates on one shard, and you must actively split/rebalance ranges as they grow. Choose hash when access is point-lookup and even load matters; choose range when workloads are range-scan heavy (time series, analytics) and you can manage the rebalancing and tail hotspot.

Many-key skew (hashing fixes) vs single hot key (bucketing/replication fixes)

Diagnose which problem you have before reaching for a tool. Uneven load across many keys is a hashing / shard-key-choice problem — fix the shard key. Load concentrated on one key is not a hashing problem — hashing cannot split one key — so fix it with sub-bucketing (near-exact, costs a read fan-out) or replication (cheap even reads, costs write fan-out and works only for read-hot keys). Using the wrong lever — resharding to fix a hot key — is the classic wasted migration.

Takeaways


Sources: DDIA (Kleppmann) ch.6 on partitioning, skew and hot spots; the Dynamo paper and Karger et al. on consistent hashing with virtual nodes; production write-ups on hot-key mitigation. See also: Rate-Limit Hot Keys (sub-counter sharding & local pre-aggregation), Consistent Hashing, and Cache Stampede. Re-authored/Deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on Shard Keys: many-key skew vs a single hot key? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Shard Keys: many-key skew vs a single hot key** (System Design) and want to truly understand it. Explain Shard Keys: many-key skew vs a single hot key from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Shard Keys: many-key skew vs a single hot key** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Shard Keys: many-key skew vs a single hot key** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Shard Keys: many-key skew vs a single hot key** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes