Course contentsShow
← System Design
Lesson 398 of 1,91911. NoSQL: Document StoresFree lesson

Config Servers and mongos Routers

The role of config servers that store cluster metadata and mongos routers that direct queries to the right shards.

Config Servers and mongos Routers

What you'll learn: How MongoDB's config servers and mongos routers work together to manage and route requests in a sharded cluster.


In a MongoDB sharded cluster, two critical components ensure the system knows where data lives and how to route queries: config servers and mongos routers. Think of them like a library's card catalog and help desk working together.

Config Servers: The Cluster Metadata Store

Config servers store all the metadata about your sharded cluster:

  • Which shard key ranges live on which shards
  • The location and status of all shards
  • Chunk distribution and boundaries
  • Database and collection configuration

They typically run as a replica set (usually three config servers) to ensure metadata remains highly available. Without config servers, the cluster wouldn't know how data is distributed across shards. If they go down, you cannot perform metadata operations like splits or migrations, though existing data access continues.

mongos Routers: The Query Director

The mongos router is the entry point for all client applications. It doesn't store data itself—instead, it acts as a smart query router:

  1. Receives queries from clients
  2. Consults config servers to determine which shard(s) hold the relevant data
  3. Routes the query to the appropriate shard(s)
  4. Aggregates results (if needed) and returns them to the client

You can run multiple mongos instances for load balancing and redundancy. Clients connect to mongos as if it were a single MongoDB instance, completely unaware of the underlying sharding complexity.

Analogy: Config servers are like the warehouse inventory database, while mongos routers are like customer service representatives who check the inventory and fetch items from the right warehouse shelves.

Key Takeaway: Config servers maintain cluster metadata (where data lives), while mongos routers use that metadata to intelligently route client queries to the correct shards.