⬡ ScalingAdvanced interactive
Database Sharding
Split one big database into many smaller ones.
hash_sharding
shard = key % 3
shard 0
empty
shard 1
empty
shard 2
empty
Each row lives on exactly one shard — writes and storage scale horizontally.
How it works
Sharding partitions data horizontally across multiple database nodes by a shard key, so each holds only a slice. It scales writes and storage past a single machine's limits — at the cost of cross-shard queries and rebalancing complexity.
Mental models
- The shard key determines which node owns each row — choose it carefully.
- Range, hash, and directory-based sharding trade locality for balance.
- Cross-shard joins and transactions are the expensive parts.
Reach for it when
- Write-heavy scale-out
- Multi-tenant isolation
- Geo-partitioning