Sharding has three different components and each components performs different functions. The following diagram shows those three components and its connectivity:

Config Servers

– Config servers store the metadata of the clusters dataset to the shards. A production sharding must have exactly three config servers. These will organize the data for Query router.

Shards (Replica set)

– Shards are responsible to store the actual data. Each shard is composed of multiple replica set, and we can define a replica set as containing one primary and one or more secondary set. As a result, shards provide high availability through replica set. The primary set alone can do write operations and secondary can do only Read operations. Furthermore, when the primary replica set goes down then one of the secondary replica set will act as master.

Query Routes (mongos)

– Application and direct mongo operations can be done through Query routers. For each request it will communicate with shards then returns the results to clients. Also, the shard setup may have multiple Query router to split the request load.