Replication In MongoDB
♦ Replication is the process of creating and maintaining the multiple copies of data across the different servers and also ensuring the copy of the data remains consistent and updated.
♦ Replica set is one of the ways of implementing the replication in MongoDB.
♦ Replica set is a speciﬁc implementation conﬁguration of replication in MongoDB.
♦ It is a group of MongoDB instances that work together to maintain the same data It consists of multiple servers.
♦ The minimum recommended conﬁguration for a replica set is three members which includes one primary and two secondary nodes.
♦ A replica set can have maximum up to 50 members but only seven voting members which are used to help in electing the primary node.
♦ A replica set can have up to 50 Members but only 7 voting members.
Advantages of using Replication:
1. Data Redundancy
2. High Availability
4. Load Balancing
5. Fault Tolerance
6. Disaster Recovery
Members of replica set:
1. Primary node
2. Secondary node
3. Arbiter node
1. Primary node :
♦ It is the primary source of data modiﬁcations, which handles all the write operations and applies all the write operations to the dataset.
♦ It keeps tracking of the replica set’s Oplog.
♦ It handles both the read and write operations from the client’s application.
♦ Secondary nodes will replicate the Oplog which is generated from the write operations from the primary node.
♦ It ensures the health and data consistency within the replica set.
2. Secondary node:
♦ These nodes will replicate the primary node Oplog and also it acts as backup, ensuring that these nodes are always up to date with the data in the primary node.
♦ Replica set can have more than two secondary nodes.
♦ Secondary nodes are used to read the data.
♦ If the primary node fails, one of the secondary nodes will be elected as the new primary node.
♦ Secondary nodes should be monitored regularly to ensure their health and performance.
3. Arbiter node:
♦ The arbiter node will not store any replica sets in it.
♦ Main use of the arbiter node is to participate in the election when the primary fails to work which helps in the situation of tie in the election process.
♦ It helps in maintaining the replica set’s fault tolerance.
♦ This does not affect the storage capacity of the replica set.
♦ It is expanded as an operation log.
♦ It is a capped collection which is present in the primary node.
♦ Oplog is used for secondary nodes to replicate the data from the primary node in an asynchronous process.
♦ The default size of Oplog is 50MB, you can increase the size of the Oplog based on your application requirements up to 50gb.
Author : Teja