System Design
5. Advanced Database ArchitectureAnimated
Horizontal Partitioning
Splitting a table by rows.
The idea
Different row sets go to different partitions, for example by user id or date.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- outlined = moved key
Range-based: keys are split into contiguous ranges, one per node. Good for range queries; risky for hot spots such as increasing ids.
- nodes:
- 4
- moved:
- 0
1/2
Each square is a key; its colour is the shard that stores it.
Step by step
- 1Choose a partition rule
- 2Assign rows to partitions
- 3Queries hit only relevant partitions
- 4Old partitions can be archived
Where it is used
Large tables.
Watch out for
A bad rule creates hot partitions.