Sunday, February 24, 2019

Replica Set in MongoDB


  • Replica Set  in MongoDB ensure high availability and redundancy.
  • Replica Set is  basically set of different  mongod processes which can run on different machines or on same machine. Typically in a prod environment, these should run on different machines/nodes.
  • All members of replica set contains same data.
  • There can be only 1  read-write member which is called primary member.
  • All others members are read only members called secondary members.
  • Data is replicated from read-write member to read only members asynchronously.
  • Optionally, there can be arbiter which does not require dedicated hardware. Arbiter is not data bearing node. It just participates is elections to obtain majority.
  • It is recommended to have add number of nodes in Mongo replica set. We typically add a arbiter to make odd number of nodes in replica set.
  • When primary node fails, or does not communicate with other nodes in replica set( for by default 10 sec), an election happens. The purpose of elections is to choose a primary in mongo replica set, so that normal operations can be resumed (write can also happen now). Election can also happen in certain other circumstances.


No comments: