Skip to content
StackDecode
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.

123456789101112131415161718192021222324252627282930N1: 8N2: 7N3: 8N4: 7
  • 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

  1. 1Choose a partition rule
  2. 2Assign rows to partitions
  3. 3Queries hit only relevant partitions
  4. 4Old partitions can be archived

Where it is used

Large tables.

Watch out for

A bad rule creates hot partitions.

Related