Topic 8.2
Partitioning
In one line
Splitting one logical dataset into smaller slices so each slice can live (and be queried) on its own node.
Think of it like this
Splitting one huge phone book into 26 smaller books, one for each starting letter. Each book is smaller and faster to search, but you need to know which book to open first.
Key ideas
- 01
Partitioning = data independence: partitions are subsets of rows; each node owns some partitions.
- 02
Range partitioning: partition by key ranges (dates, ids) — great for range queries, hot spots at the boundary.
- 03
Hash partitioning: hash of key → partition — even distribution, but range queries become scatter-gather.
- 04
List partitioning: by enumerated value (e.g. tenant/region).
- 05
Partitions enable parallel query and independent failure/backup of slices.
- 06
Pagination caveat: ORDER BY across partitions requires a merge step — cross-partition queries are slower.
Java / Spring map
- →
Postgres declarative partitioning; JPA transparent to it (you partition at the DB layer).
Code & diagrams
Same table, three different ways to slice it — each with a different weak point.
Explain without notes
Range vs hash partitioning for an events table — which has better write distribution, which reads better?
Practice
Partition the mock orders table by month (range) and by user-hash; compare hotspot behavior.
Trade-offs
- ↔
Hash kills range scans; range creates hot boundaries. The classic dial: choose by dominant access pattern.
Run it in production
You've designed it. Now build, operate, and break the same idea hands-on in the DevOps courses:
Completion checklist
I can distinguish partitioning from sharding and pick the split key type.