

It’s important to remember that the config servers also work as replica sets. Finally, the result of the query will be returned to the application.The mongos instance consults the config servers to check which shard contains the required data set to send the query to that shard.The application communicates with the routers (mongos) about the query to be executed.

The following diagram from the official MongoDB docs explains the relationship between each component: Config ServersĬonfiguration servers store the metadata and the configuration settings for the whole cluster. This MongoDB instance is responsible for routing the client requests to the correct shard. Mongos act as the query router providing a stable interface between the application and the sharded cluster. For example, a 2 TB data set can be broken down into four shards, each containing 500 GB of data from the original data set. The combination of multiple shards creates a complete data set. Shards can be deployed as replica sets to increase availability and provide redundancy. That means sharded clusters consist of three main components:Ī shard is a single MongoDB instance that holds a subset of the sharded data. MongoDB sharding works by creating a cluster of MongoDB instances consisting of at least three servers. MongoDB supports horizontal scaling through sharding-one of its major benefits, as we’ll see below. However, horizontal scaling increases the complexity of underlying architecture. Distributing the load reduces the strain on the required hardware resources and provides redundancy in case of a failure. This method divides the dataset into multiple servers and distributes the database load among each server instance. However, upgrading a single server is often challenged by technological limitations and cost constraints. The process involves upgrading the CPU, RAM, and storage capacity. Vertical scaling is the traditional way of increasing the hardware capabilities of a single server. To mitigate this problem, there are two types of scaling methods. High query rates can stress the CPU, RAM, and I/O capacity of disk drives resulting in a poor end-user experience. When dealing with high throughput applications or very large databases, the underlying hardware becomes the main limitation. In MongoDB, sharding is achieved by splitting large data sets into small data sets across multiple MongoDB instances. Sharding is the process of distributing data across multiple hosts. Use the right-hand menu to navigate.) What is sharding? (This article is part of our MongoDB Guide. A step-by-step tutorial on setting up sharding.This comprehensive article explores sharding in MongoDB.
