What is sharding (sharding)?
Sharding is a horizontal-scaling method where a database's data is split into several independent fragments (shards), with each shard stored on a separate server.
How it works
Instead of one huge database holding all the data together, several "mini-databases" get created, each holding only part of the information. For example:
- users with IDs 1 to 1,000,000 live on server A,
- 1,000,001 to 2,000,000 live on server B,
- and so on.
Why it's needed
- Speed. Each server handles less data, so queries run faster.
- Scalability. New servers can be added as data grows, without overloading the old ones.
- Fault tolerance. If one shard fails, the rest keep working.
The complications
- You need to choose the right shard key (by ID, region, etc.).
- Queries that span multiple shards get harder (e.g. aggregates across all users).
- Extra logic is needed in the application or middleware to route requests.
Summary: Sharding is a way to "cut up" a database into independent pieces to increase its performance, scale, and resilience.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.