Shard in MongoDB

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

May be interested

  • Learn about Java Driver in MongoDBLearn about Java Driver in MongoDB
    in the following article, we will introduce you some basic features of mongodv java driver as well as how to deploy and apply in practice.
  • Install MongoDBInstall MongoDB
    instructions for installing mongodb on windows.
  • Map Reduce in MongoDBMap Reduce in MongoDB
    in mongodb documentation, map-reduce is a data processing system that condenses a large amount of data into useful overall results. mongodb uses mapreduce command for map-reduce operation. in general, map reduce is used to handle large data sets.
  • Aggregation in MongoDBAggregation in MongoDB
    aggregation can be understood as aggregation. the aggregation operation handles data records and returns calculated results. the operations group the values ​​from multiple documents together, and can perform multiple operations on the grouped data to return a single result. in sql, count (*) and group by are equivalent to aggregation in mongodb.
  • Data modeling in MongoDBData modeling in MongoDB
    data in mongodb has a flexible schema. documents in the same collection need not have the same set of fields or structures, and common fields in collection documents can keep different data types.
  • How to use Aggregation Pipeline in MongoDBHow to use Aggregation Pipeline in MongoDB
    if you are using mongodb's mapreduce, it is best to switch to aggregation pipeline for more efficient computation.
  • GridFS in MongoDBGridFS in MongoDB
    gridfs is the mongodb specification for storing and collecting large files such as images, audio, video files, etc. it is a type of file system to store files but its data is stored inside mongodb collections. .
  • Query analysis in MongoDBQuery analysis in MongoDB
    analyzing queries is a very important aspect to assess the effectiveness of database and the effectiveness of the designed index. we will explore the two most frequently used queries, $ explain and $ hint.
  • Projection in MongoDBProjection in MongoDB
    in mongodb, projection's meaning is to select only the necessary data instead of selecting the entire data of a document. if a document has 5 fields and you only need 3 fields, you should only select 3 fields from that document.
  • Reference Database in MongoDBReference Database in MongoDB
    as shown in the relationship chapter in mongodb, to deploy a standardized database structure in mongodb, we use the referenced relationship concept, also known as manual references, in which we manipulate to store the id of the documents referenced in another document.