MongoDB & NoSQL (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)
What is the Sharding Architecture in MongoDB (mongos, Config Servers, Shards)?
senior LevelCode ExampleSystem DesignDatabases & SQL
In Simple Words: MongoDB achieves horizontal scale-out by partitioning large collections across clusters:
- Shards: Each shard holds a subset of the sharded data. In production, each shard is deployed as a 3-node Replica Set.
- Config Servers: A dedicated 3-node replica set storing cluster metadata, shard boundaries, and routing mappings.
mongos(Query Routers): Stateless routing proxies that applications connect to. Inspects queries, routes requests directly to the correct shard, and merges multi-shard responses.
text
Sharding Cluster Topology:
[Application Clients]
│
[mongos Router]
┌──────┴──────┐
▼ ▼
[Config Replica Set] (Metadata)
│
┌─────────────┴─────────────┐
▼ ▼
[Shard 1 (Replica Set)] [Shard 2 (Replica Set)]