MongoDB Sharding

Shard metadata are stored in config server replica set (CSRS).

Query router (mongos) cache this data and use it to route read and write operations to the correct shards. mongos updates the cache when there are metadata changes for the cluster, such as adding a shard. Shards also read chunk metadata from the config servers. Mongos provide the only interface to a sharded cluster from the perspective of applications. Applications never connect or communicate directly with the shards.

A MongoDB replica set are collections of mongod that shares replication data. Each replica set can only have one primary, with multi primary deployments possible with sharding, where each shard is a replica set with its own primary.

mongodb sharded cluster

References