Skip to main content
InterviewHubPRO
Section Overview
Q21

Question 21 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

42%
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:

  1. Shards: Each shard holds a subset of the sharded data. In production, each shard is deployed as a 3-node Replica Set.
  2. Config Servers: A dedicated 3-node replica set storing cluster metadata, shard boundaries, and routing mappings.
  3. 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)]