Sharding Strategies & Celebrity Hot Spots
Hash vs. range sharding, cross-shard JOINs, and handling viral hot partitions.
In plain words
Splitting a giant library into 10 buildings by book number keeps each building manageable - unless one famous book has a million people crowding into Building #4.
Think of it like…
Splitting checkout lines by last name A–Z: almost equal, except "S" and "M" get longer lines unless you hash names randomly.
Theory & how it works
Range Sharding vs. Hash Sharding
Range sharding (e.g., IDs 1–1M on Shard 1) makes range queries fast, but risks hot spots if new IDs always increase. Hash sharding (hash(key) % N or consistent hashing) spreads writes evenly, but range queries must scatter-gather across every shard.
Remember: once you shard, cross-shard JOINs and multi-shard ACID transactions become slow and fragile - co-locate related rows by choosing a smart shard key like tenant_id or user_id.
Key points & practical guide
Summary checklist
- Exhaust vertical scaling + caching + read replicas BEFORE sharding
- Pick a high-cardinality shard key aligned with main queries
- Use key salting or caching for celebrity hot spots
When to use it
- Data exceeds ~5–10 TB or writes exceed a single primary’s capacity
Watch out for
- Sharding by timestamp - puts 100% of live inserts onto one active shard