The difference between three clusters of mongodb (replicaset/s hardening/master-slaver)

  mongodb, question

The difference between three clusters: replicaset/s hardening/master-slaver


First, the last one is Master/Slave, not slave. This method is basically no longer recommended, only copying data from Master to Slave, and does not provide high availability. once Master node fails, it is more difficult to handle. The specific details will not be mentioned. It is not recommended anyway.

Replica Set

This is often called the replication set. There are several main targets for replication sets:

  • High availability (main target): automatically switch to other nodes when one node fails;
  • Data redundancy (main target): data is copied to n nodes to increase data security and provide a basis for high availability.
  • Functional isolation (secondary goal): use different nodes to isolate certain functions with special requirements, such as using one node for OLAP operations (large-scale resource occupation), using one node for remote disaster preparedness (performance requirements are not as high as those in the local area), separation of reading and writing, etc.

Sharded Cluster

That is, the fragment set. The main design objectives of the shard set are:

  • Horizontal expansion: when a server cannot meet the demand, we can choose vertical expansion (adding server hardware). although it is simple, it is easy to reach the limit and faces obvious disadvantages such as high cost. The cheaper way is to use n servers to form a cluster to meet the sy stem requirements. This is the main design goal of piecewise set.
  • Shorten response time: since data can be distributed to multiple servers, naturally the processing pressure of each server will be reduced and the processing time will be shortened;

There is a problem here: suppose the probability of each server failing isx%, thennThe probability of one server failing isx% * nIf high availability design is not done, the probability of cluster failure will increase in proportion to the number of machines, which is not acceptable in engineering. Fortunately, we already have a highly available solution, which is replication set. Therefore, MongoDB’s fragmented cluster requires each slice to be a replication set (of course, the test environment can also use a single node, which is not recommended in the production environment).


This is probably the case. Everyone has different design goals and each does his own thing.