The concept of MongoDB replica sets and shards

Source: Internet
Author: User

Replica set (Replica set):

In layman's words, a replica set is a cluster, master-slave replication, read-write separation, and failover.

replica set is Mongodb The original master-slave mode upgrade version, the official no longer recommended the use of master-slave mode.

MongoDB the replica set differs from master to subordinate, and the master/slave will stop all services after the host is down, and the replica will take over the primary node when the host is down, and there will be no downtime.

MongoDB replication requires a minimum of two nodes. One is the master node, which handles client requests, and the rest is the slave node, responsible for replicating the data on the master node.

MongoDB the common collocation methods of each node are as follows: one master and one slave, one master and many from.

all operations on which the master node records Oplog , the primary node is periodically polled from the node to get these operations, and then perform these operations on its own copy of the data, ensuring that the data from the node is consistent with the primary node.

MongoDB the copy structure diagram looks like this:

Ps: This picture reads and writes from the master node, can actually set the read operation to walk from the node, but the write operation can only be on the primary node.

Replica set Features:
    • N nodes of a cluster
    • Any node can be used as the master node
    • All write operations are on the primary node
    • Auto Fail-Over
    • Automatic recovery

Shard (sharding)

in the Mongodb There is another cluster, the Shard technology , can meet MongoDB the demand for a significant increase in data volumes.

Shards are distributed to individual nodes after splitting the data, so the data on each node is different, which is the biggest difference from the replica set.

One of the benefits of sharding is splitting the data into different nodes, which can reduce the stress of writing.

when MongoDB when storing large amounts of data, a machine may not be sufficient to store data or may not be sufficient to provide acceptable read and write throughput. At this point, we can divide the data on multiple machines so that the database system can store and process more data.

shows the MongoDB using the Shard cluster structure distribution in:

There are three main components as described below:

  • Shard:

    used to store actual data blocks, shard server role can be set by several machines a

  • Config Server:

    Mongod instance, which stores the entire Clustermetadata , which includes Chunk information.

  • Query Routers:

    Front-end routing, which the client accesses, and makes the entire cluster look like a single database, the front-end application can be used transparently.

For replica sets and shards , it is only a concept and a theory that can be learned in depth.

The concept of MongoDB replica sets and shards

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.