What is the difference between sharding and partitioning?
Partitioning splits a big table into smaller parts, often inside one database. Sharding is partitioning where the parts live on different servers, so both data and load are spread across machines.
Explain it simply
Think of a huge register of student records. Partitioning means tearing it into volumes (A to H, I to P, Q to Z) and keeping them in the same cupboard. Sharding means giving each volume to a different office in a different building.
Partitioning: one database server, but a table is split by rule (by date, by region) so queries touch less data and old partitions can be dropped easily. It helps performance and maintenance, not capacity beyond one machine.
Sharding: horizontal partitioning across multiple servers. Each shard holds a subset of rows and handles only its subset of traffic, so you can grow beyond the limits of one machine.
Sharding adds complexity: queries must be routed to the right shard, joins across shards are expensive, transactions across shards are hard, and rebalancing data when adding shards needs a plan.
Many people use "partitioning" and "sharding" loosely, so say which sense you mean.
Example
Orders table, 400 million rows.
Partitioning (one server): orders_2025_q1, orders_2025_q2 ...
query for Q2 reads only that partition.
Sharding (many servers): customer_id % 4
shard0: ids ending 0 mod 4 -> server A
shard1: ids ending 1 mod 4 -> server B ... and so onWhat to say in the interview
"Partitioning divides data into smaller pieces, usually within one database; sharding places those pieces on separate servers to scale storage and throughput. I would exhaust indexing, caching, replicas and vertical scaling first, since sharding makes joins, transactions and rebalancing harder."