What is Sharding in MongoDB?

Sharding is the method of distributing data across multiple machines, enabling horizontal scaling. MongoDB uses sharding to support deployments with large datasets and high throughout operations. Horizontal scaling involves dividing the system datasets and loading over multiple servers, adding additional servers to increase capacity as required. In MongoDB a sharded cluster consists of several: a)shards; b)routers; c) config server replica sets.

A shard is a replica set that contains a subset of the sharded collection also known as chunks. A replica set consists of one or more mongod nodes that all maintain the same data set. Replica set provides high availability. Sharding allows us to partition the data across multiple replica sets and as a result, boast the database resources.

The routers or mongos act as query routers for client applications, handling both read and write operations. The router caches the metadata from the config server in order to properly route requests to relevant shards or shards.

The config servers tear all the metadata for a sharded cluster. The metadata includes state and organization of all data and components within the sharded cluster.

The benefits of Sharding are, it increases read/write throughout, increases storage capacity, and has high availability.