Skip to content
Horizontal Scale-Out & Partitioning Sandbox

Sharded Cluster & mongos Router Lab

Explore distributed horizontal sharding. Observe how the stateless mongos router routes targeted queries using shard key ranges, why queries missing the shard key scatter-gather across all shards, and how the chunk balancer migrates data between shard replica sets.

Horizontal Sharding, mongos Router & Chunk Balancer

Observe mongos single-shard routing vs scatter-gather queries and automatic chunk migration across replica sets.

mongos Query Router

Stateless routing daemon. Caches routing table from Config DB. Clients connect directly to mongos on port 27017.

Config Replica Set (CSRS)

Stores cluster catalog, database mappings, and chunk range boundaries in config.chunks with two-phase commit lock.

Chunk Balancer

Background round-robin process. Triggers migration when chunk difference between shards exceeds the migration threshold.

Shard 01 (Replica Set: rs-shard-01)3 Chunks
chunk-1Range: [MinKey .. 1000)
450 docs
chunk-2Range: [1000 .. 2000)
820 docs
chunk-3Range: [2000 .. 3000)
610 docs
Shard 02 (Replica Set: rs-shard-02)1 Chunks
chunk-4Range: [3000 .. MaxKey)
390 docs
MONGOS_LOG:Cluster balanced across 2 shards. Shard key: { user_id: 1 }.