Shard in MongoDB

Sharding is a process of storing data records across multiple devices and it is a method of MongoDB to meet the requirement for increasing data. When the size of the data increases, a single device cannot be enough to store data.

What is sharding?

Sharding is a process of storing data records across multiple devices and it is a method of MongoDB to meet the requirement for increasing data. When the size of the data increases, a single device cannot be enough to store data. Sharding solved this problem with expanding horizontal scaling. With Sharding, you add more devices to support the increase in data and the requirements of read and write operations.

Why use Sharding?

In Replication, all write operations are performed at the primary node.

Potential queries still go to the primary node.

A single Replica Set has a limit of 12 nodes.

Memory cannot be large enough when the data set is large.

Local Disk is not big enough.

Vertical scaling is too costly.

Sharding in MongoDB

Below is a Sharding diagram in MongoDB using Sharded Cluster.

Shard in MongoDB Picture 1

In the diagram above, there are three main components:

Shards : used to store data. They provide high availability and uniform data. In the creation environment, each Shard is a separate Replica Set.

Config Servers : save Cluster metadata. This data contains a mapping of Cluster to Shards data set. Query Router uses this metadata to direct specific Shards operations. In the creation environment, sharded clusters have exactly 3 Config Servers.

Query Routers : it is basically an instance, interfaces with the Client Application and directs operations to the appropriate Shard. Query Router processes and directs operations to the Shard and then returns the results to the client. A Sharded Cluster can contain more than one Query Router to divide the request load from the Client. A Client sends requests to a Query Router. In general, a Sharded Cluster has many Query Routers.

According to Tutorialspoint

Previous article: Replica Set in MongoDB

Next article: Create Backup in MongoDB

4 ★ | 1 Vote | 👨 206 Views
« PREV POST
NEXT POST »