ScalingIntermediate
Partitioning vs sharding — what is the difference?
“Explain both and when each is appropriate.”
What this tests
- Distinguishing the two
- What crosses the boundary
Answers by level
Read the beginner answer first and notice what is missing.
Partitioning splits one table into pieces within one database — same machine, same transactions, same joins. It keeps a huge table operable (small indexes, fast VACUUM, instant retention by dropping a partition) but adds no capacity. Sharding splits data across separate database nodes and is the only thing that adds write capacity beyond one machine.
The cost of sharding: joins, transactions, uniqueness and aggregates across shards move into the application or become impossible.
Green flags · Red flags
Strong green flag · Says partition first, shard last.
Green flags
- One database vs many machines
- Partitioning adds no capacity
- Names lost cross-shard guarantees
Red flags
- Treats them as synonyms
- Thinks partitioning scales writes
Follow-up questions
F1
Does partitioning increase write throughput?
Scenario
An events table is 2 billion rows on one instance and only queried by time range. Partition or shard?