System Design
5. Advanced Database ArchitectureAnimated
Database Sharding
Splitting data across multiple databases.
The idea
Each shard holds part of the data. This scales storage and writes beyond one machine.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- outlined = moved key
Hash-based: shard = hash(key) mod N spreads keys evenly, but range queries need every shard.
- nodes:
- 4
- moved:
- 0
1/2
Each square is a key; its colour is the shard that stores it.
Step by step
- 1Choose a shard key
- 2Route each row to a shard
- 3Queries go to the right shard
- 4Add shards as data grows
Where it is used
Very large datasets.
Watch out for
Cross-shard queries and rebalancing are hard.