SysDesign study
Offline — showing the cached copy.
Home / Software System Design / 7. Sharding and partitioning

7. Sharding and partitioning

One-liner. When one machine can't hold the data, split it by a key you'll always query by.

Memorize

  • Range partitioning: good scans, risk of hot spots (time-ordered writes).
  • Hash partitioning: even spread, kills range queries.
  • Consistent hashing: adding nodes moves ~1/N of keys instead of everything.
  • Hot key (celebrity user, viral item) needs salting, caching, or request coalescing.
  • Resharding is the hard part: plan for double-writes + backfill + cutover.
  • Shard key = the key present in every hot query; otherwise you fan out to all shards.
HASH SHARDING WITH CONSISTENT HASHING Router Shard 1 Shard 2 Shard 3 Replicas
Hash sharding with consistent hashing

Trap. Sharding by created_at for a feed — every write lands on one shard. Do this. Check the shard key against your top three queries.

Check

A time-series table is sharded by timestamp and one shard takes all writes. Best fix?