Why it matters
Sharding is what enables databases to scale beyond single machines. Understanding the trade-offs — and when to shard vs alternatives — is major architecture decision.
Advertisement
The architecture
Sharding key: column determining which shard a row belongs to. Common: user_id, tenant_id, geographic region.
Sharding strategy: hash (even distribution), range (localized queries), geographic.
Advertisement
How it works end to end
Cross-shard queries: require distributed execution. Slow. Best avoided by design.
Rebalancing: adding nodes requires moving data. Consistent hashing minimizes movement.
Distributed transactions across shards need 2PC or sagas. Avoid when possible.
Alternative: managed distributed DBs (Spanner, CockroachDB, Yugabyte) handle sharding automatically.