When One Database Server Is Not Enough

Vertical scaling has a ceiling — and a punishing price curve as you approach it. At some point your single Postgres or SQL Server box runs out of CPU, RAM, IOPS, or all three, and the answer stops being "a bigger box" and starts being "more boxes, each owning a slice of the data". That's sharding: horizontal partitioning of a logical dataset across N physical stores so that any single shard handles 1/N of the work.

Sharding solves a real problem (write throughput, dataset size, blast radius) and creates several new ones (cross-shard joins, hot shards, rebalancing, distributed transactions). Below is when to reach for it, how to pick a shard key you won't regret, and the operational realities that don't make it into the design doc.

Before you shard
  • Your single DB is at 80% CPU and you're scared to deploy
  • You think sharding by user_id % N is fine until you have to add a shard
  • One of your shards is at 95% disk and the rest are at 30%
  • You can't do a cross-shard JOIN and didn't plan for that

This is the sharding playbook — when to actually shard, how to pick a key, hash vs range vs directory, and how to rebalance without a 3-day outage.