Database Reference
In-Depth Information
Understanding sharding modules
In order to establish sharding for a database in MongoDB, we need to use some different
modules and components. Each module is responsible for a specific task.
The first module to study is a shard. Each shard, whether a single mongod instance or a
replica set, is responsible for storing data in a machine. We recommend that you use a rep-
lica set as a shard in a production environment, but you can use a single mongod instance
for development and testing environments.
The next component is a query router. The query router's task is to get all requests from ap-
plications and clients, route them to the corresponding shard, and finally, return the result
to the client. This module is the only interface that has clients and all applications interact
with it. The sharded cluster can include one or more query routers and adding more query
routers can improve the sharded cluster's performance because user requests will be divided
between query routers. However, note that adding more query routers than shards increases
latency because all query routers perform routing to a single shard. The mongos process is
the query router module that routes requests from clients.
The last module is the configuration server. This module collects metadata about sharded
clusters, shard configurations, each node status, and the relationship between them. With
the help of this module, query routers can send requests to correct nodes and shards. In a
production environment, the sharded cluster has three configuration servers. However, in
some situations, one or two configuration servers might be unavailable, although at least
one configuration server must be available to have a functional sharded cluster.
The following diagram shows a sharded cluster and the relationship between each compon-
ent:
Search WWH ::




Custom Search