Sharding Concepts: Chunks, Balancer, and Shard Keys
Learners will define chunks and explain how the balancer moves them across shards to maintain an even distribution of data.
What Is Sharding?
Sharding is MongoDB's horizontal scaling strategy. Instead of storing all data on a single replica set, a sharded cluster divides the data across multiple shards, each of which is itself a replica set. This lets you scale storage, throughput, and memory horizontally by adding more shards as your data grows.
Sharded Cluster Components
A sharded cluster has three roles: Shards — replica sets that store the actual data. mongos — a query router that receives client connections and routes operations to the correct shard(s). Config servers — a replica set that stores cluster metadata, including the shard key ranges and chunk locations. Clients always connect to mongos, never directly to shards.
// Connect to the cluster via mongos (same URI format as a standalone)
const client = new MongoClient('mongodb://mongos-host:27017/mydb')All lessons in this course
- Sharding Concepts: Chunks, Balancer, and Shard Keys
- Choosing a Shard Key: Cardinality, Frequency, Monotonicity
- Ranged vs Hashed Sharding Strategies
- Zone Sharding: Pinning Data to Regions