Careeroza
When to shard
Sharding
๐น What is Sharding?
Sharding is a method of splitting large data across multiple machines (servers).
Instead of storing all data in one server
MongoDB distributes data into smaller parts called shards
Simple:
Big data โ split โ store on multiple servers
๐น Why Sharding is Used
- Handles very large data
- Improves performance
- Supports horizontal scaling
๐น How it Works
- Data is divided based on a shard key
- Each shard stores a portion of data
- MongoDB automatically routes queries
๐น Example
Users collection with millions of records:
- Shard 1 โ users AโM
- Shard 2 โ users NโZ
Data is distributed
๐น When to Use Sharding
Use sharding when:
- Data size is very large
- Single server cannot handle load
- Queries are becoming slow
- High read/write traffic
- Need to scale horizontally
๐น When NOT to Use
- Small datasets
- Low traffic applications
- Can be handled with indexing or replication
๐น Key Term
Shard Key โ field used to divide data
Choosing good shard key is very important
Simple Understanding
- Sharding = distribute data
- Helps with scaling and performance