What is a hot partition and how do you fix it?
A hot partition is a shard or partition that receives far more traffic than the rest, so it becomes the bottleneck. Fix it with better keys, key salting, splitting the hot shard, or caching hot items.
Explain it simply
Picture a mall food court where everyone lines up at one stall while the others stay empty. Total capacity is large, but throughput is limited by that single queue.
In a sharded store, causes include a celebrity account with millions of followers, a viral product during a sale, or a key based on time so all current writes hit one partition.
Fixes:
- Better key: choose one with a more even spread, or hash it.
- Salting: add a random suffix to a hot key (post:42#0 to post:42#9) so its writes spread over ten partitions; reads then query all ten and combine.
- Split the hot shard into smaller ranges.
- Cache hot reads in front of the store so most never reach the shard.
- Rate limit or queue writes to a single hot item.
First detect it: monitor per-partition load, not just cluster averages, because the average looks healthy while one node fails.
Example
A like counter for one viral post receives 50,000 writes per second.
Single key post:42 -> one partition takes 50,000/s (hot)
Salted keys post:42#0..9 -> each takes about 5,000/s
Read total = sum of the 10 counters (cached for 1 s)What to say in the interview
"A hot partition is an uneven load on one shard. I detect it with per-partition metrics, then use better keys, salting for hot items, shard splitting and caching. For counters I spread writes over several sub-keys and sum on read."