1. What is Sharding?
Sharding is a method of distributing data across multiple servers (or
nodes) to improve performance, scalability, and storage capacity in a
database system — especially in NoSQL databases like MongoDB,
Cassandra, and HBase.
It’s like dividing a big table into smaller parts (shards) so that each
server handles only a portion of the data.
2. Why Sharding is Needed
As data grows, a single server may face problems:
Storage limits (too much data)
Slow queries (too many requests)
High load (CPU and memory usage)
Sharding solves this by splitting data horizontally — each shard stores
a subset of rows (not columns).
3. How Sharding Works
1. Shard Key – A field (or combination of fields) used to decide
which shard a document or record belongs to.
Example: In a MongoDB “students” collection, student_id
could be the shard key.
2. Shards – Each shard is a separate database server (or cluster)
containing part of the data.
3. Config Server / Metadata – Keeps track of which shard holds
which data ranges.
4. Router (Query Router) – Routes queries to the correct shard(s)
based on the shard key.
4. Example
Suppose we have a NoSQL collection:
student_id name branch city
1 Raj CSE Gwalior
2 Neha ECE Delhi
3 Aman ME Pune
If we shard by student_id:
Shard 1: student_id 1–1000
Shard 2: student_id 1001–2000
Shard 3: student_id 2001–3000
When a query asks for student_id = 1200, the router sends it
directly to Shard 2 only.
5. Advantages of Sharding
Scales horizontally (add more servers easily)
Increases read/write throughput
Distributes data evenly across multiple nodes
Avoids single point of failure (in distributed setups)
6. Challenges / Disadvantages
Complex setup and maintenance
Requires careful choice of shard key (bad key → uneven load)
Data migration between shards can be costly
Some queries (that don’t use shard key) must scan all shards
7. NoSQL Databases That Use Sharding
MongoDB – Built-in automatic sharding
Cassandra – Uses consistent hashing (automatic sharding)
HBase – Region-based sharding
Couchbase – Uses vBuckets for sharding
🧠 Summary
Concept Description
Splitting large data horizontally into smaller chunks stored
Sharding
on different servers
Shard
Attribute used to decide which shard a record belongs to
Key
Goal Improve scalability, performance, and data distribution