Partitioning is the general idea of splitting a data set into smaller pieces by a rule, such as a date range, a list of regions or a hash of a key. Sharding is horizontal partitioning where the pieces live on different servers, so each machine stores and serves only its share of the rows. Every shard is a partition, but not every partition is a shard: PostgreSQL table partitioning splits one table into child tables on the same server, which speeds up queries that touch one range and makes dropping old data cheap, but it adds no capacity. Shard when a single machine can no longer hold the data or absorb the write load; partition inside one database when you want pruning and easier maintenance.
Partitioning and sharding both split a big table into smaller pieces. The difference is where those pieces live. Partitioning splits one table into parts by a rule, like one partition per month. All of them stay on the same database server. Ask for March orders, and the planner skips every other partition. Deleting last year is just dropping a partition. But it is still one server, with the same disk and the same CPU.
Sharding puts the pieces on different servers. A router hashes each user ID to find the shard that owns it. Now each machine holds only its share of the rows, so storage and write throughput grow with every shard you add.
The price shows up in queries that span shards. A query across all users has to ask every shard and merge the answers, and one hot key can still overload a single machine. So every shard is a partition, but not every partition is a shard. Partition for pruning and easy maintenance. Shard when one machine can no longer hold the data, or absorb the writes.
| Aspect | Sharding | Partitioning |
|---|---|---|
| Scope | Rows split across separate servers | Any split of data, by rows or by columns, on one node or many |
| Main goal | More storage and write throughput than one machine can offer | Query pruning, cheaper maintenance, data locality |
| Who routes queries | The application, a proxy, or the database router maps each key to a shard | Often the database planner, invisibly |
| Joins and transactions | Cross-shard joins and transactions are slow or unsupported | Still one server, so joins and transactions work as usual |
| Adding capacity | Requires moving data; consistent hashing or many small virtual shards limit how much | Not the point; add partitions as new ranges arrive |
| Examples | MongoDB sharded clusters, Vitess over MySQL, Cassandra token ranges | PostgreSQL partitions by month, a table split into hot and cold columns |
Shard when
The data set or its write rate no longer fits one primary, even a large one.
Partition within one database when
Queries usually filter on one dimension, like time, and could skip most of the table.
Products use these words differently. MongoDB and Elasticsearch call their distributed pieces shards. Kafka and Cassandra call them partitions even though they are spread across brokers or nodes. Bigtable and HBase say tablets and regions. In an interview, define the term once ("by sharding I mean splitting rows across servers by a key") and the naming question goes away.
A good shard key has many distinct values, spreads load evenly, and matches the way data is read, so most requests touch one shard. Hashing a user ID spreads load well but makes range scans across users expensive. Range partitioning by time keeps scans cheap but sends all new writes to the newest partition.
Hot keys break even a good scheme. A celebrity account or a viral product can overload the shard that owns it, so designs add caching in front, split the hot key into sub-keys, or give it dedicated capacity. Secondary indexes add another choice: a local index per shard needs scatter-gather reads, while a global index needs extra writes on every update.
Sharding comes up in nearly every design once the data stops fitting on one machine. The interviewer is not checking that you know the word. They want the shard key, the reason for it, what happens to queries that do not include it, and how you add capacity later.
“I would shard the messages table by conversation ID with consistent hashing, because almost every read is "recent messages in one conversation", so it stays on one shard. Queries by user go through a separate index keyed by user ID. To add capacity we split virtual shards rather than rehashing everything.”
Very nearly. Horizontal partitioning splits rows into groups; sharding is horizontal partitioning where the groups are stored on different servers.
Splitting by columns or by table instead of by rows: for example, moving large, rarely read columns to a separate table or store so the common queries scan less data.
High cardinality, an even spread of reads and writes, and alignment with the main access pattern so that most requests can be answered by one shard.
When one primary cannot keep up with the write rate or hold the data, after you have tried vertical scaling, read replicas and caching. Sharding adds lasting complexity, so it should be a measured decision.
Hash, range and directory sharding, tenants, hot keys and resharding.
Partitioning schemes, secondary indexes and rebalancing in depth.
Partitioning inside one server: pruning and dropping old data.
Partitions as the unit of ordering and parallelism in a log.
Consistent hashing, replication and adding nodes.
Sharding tweets and timelines, and the celebrity hot-key problem.
Range partitioning, splits and cross-shard transactions.
Partition keys, clustering keys and token ranges.
Unique IDs without a single sequence once writes are sharded.
Knowing the trade-off is half of it
Practise saying it under follow-up questions: a timed system design interview with an AI interviewer that probes your choices and grades against a rubric.