← Back to list

Partitioning vs Sharding: The Difference Every Backend Engineer Should Know

You are mid-way through a system design interview, confidently whiteboarding your database architecture. You casually drop the word: “…and…

Divyanshu Deepam · 2026-05-28 13:13 · 1 claps · 2.9 min read
#system-design-interview #database #scalability #backend-development #distributed-systems
Open on Medium ↗
Wiki topics: 🌐 · Web Development 🏛️ · Architecture

Partitioning vs Sharding: The Difference Every Backend Engineer Should Know

You are mid-way through a system design interview, confidently whiteboarding your database architecture. You casually drop the word: “…and then we’ll just shard the database.” The interviewer leans forward, smiles, and asks a devastatingly simple follow-up: “Why? Why can’t we just use database partitioning here?”. Suddenly, you freeze.

Without a crisp, production-grade mental model of the difference between the two, even experienced engineers get caught off guard. Whiteboard cheat sheets give you clean, sanitized definitions: Partitioning is local; sharding is distributed. But when your system is melting down, textbook definitions won’t save you. Let’s look at the actual operational differences, the hidden bottlenecks, and how to choose between them.

Partitioning is the splitting of data into smaller parts for manageability or performance. Partitioning is mainly for manageability and improving the performance, like if you want to have faster queries.

Sharding is a special type of partitioning where partitions are on different machines. It is horizontal scaling in its true sense.

All sharding is partitioning, but not all partitioning is sharding.

Partitioning does not necessarily mean distributed systems.

Sharding becomes necessary when a single machine can no longer handle the storage or throughput requirements. And that’s when you have to use the consistent hashing as well.

The main goal of sharding is to have:

  • more throughput
  • more storage capacity

Scenario 1: The Query Trap

Imagine you built an ecommerce platform. Your Orders table has ballooned to 500 million rows, and your latency graphs look terrible. Queries fetching recent orders are crawling.

What do you do ?

The best approach is to partition by date or month. Queries become faster , old partitions can be archived. This is easy on maintenance and no extra machine cost.

The Engineering Benefit:

  • Partition Pruning: When a user checks their recent orders, the database query planner instantly ignores 95% of the table and searches only the specific month’s partition file.
  • Zero-Cost Data Retention: When data gets old, you don’t run a massive, CPU-locking Delete query. You simply drop or archive the entire historical partition file instantly

At this point, partitioning solves query efficiency — but not machine capacity.

Scenario 2: The Infrastructure Ceiling

Now imagine your platform explodes in popularity. You hit 50 million active users, and your primary database machine is choking on write throughput. The CPU is pinned, disk I/O is saturated, and your connection pool is exhausted.

What do you do now ?

Now , partitioning alone is not enough because the bottleneck is no longer Query Optimisation. So now you must do Sharding.

Once CPU, RAM, storage or write throughput starts becoming bottlenecks for DB machine , you think of Sharding.

You can map User Id 1–10M to Shard A 10M-20M to Shard B , and so on.

What did you gain by this and how does it improve write throughput in your scenario ?

The write requests will get distributed among different shards. The throughput increases because suppose earlier you had 1 machine with ability to support 10,000 QPS now you have 10 such machines (shards) so you can simultaneously process 100,000 Queries each second.

But like everything in life , Sharding is not free optimisation , its a tradeoff. You did gain on throughput , memory , storage but there are downsides as well. This leads us to…

Sharding is a Tax… For starters, it introduces overhead of data rebalancing, since your data based on your shard key will be mapped to different DB machines now. If you have to run queries which have lot of joins , that becomes really costly or flat-out unsupported. You are forced to handle complex join logic in your application layer. If you dont choose your shard key carefully based on your query pattern then one shard can become hotspot and you come back to square one, dealing with same problem which you were trying to solve via Sharding.

Hence when beginners think “Sharding increases scalability” , Senior Engineers have a different mindset :

Sharding is expensive and should be avoided until necessary

Mental Model to decide when to use Partitioning vs Sharding

Mental Model to decide when to use Partitioning vs Sharding

Partitioning helps you manage data better. Sharding helps you survive scale.

Good engineers don’t shard because it sounds advanced. They shard only when a single machine becomes the bottleneck.


메타데이터
post_id
de3ee7b2c8f3
slug
partitioning-vs-sharding-the-difference-every-backend-engineer-should-know-de3ee7b2c8f3
url
https://medium.com/@divyanshudeepam/partitioning-vs-sharding-the-difference-every-backend-engineer-should-know-de3ee7b2c8f3
canonical_url
https://medium.com/@divyanshudeepam/partitioning-vs-sharding-the-difference-every-backend-engineer-should-know-de3ee7b2c8f3
author_url
https://medium.com/@divyanshudeepam
status
ok
fetched_at
2026-06-09 15:37:30