DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

abhishekjaindba
abhishekjaindba

Posted on • Originally published at thedbadmin.com

Delayed replica set Member in MongoDB

What is Delayed replica set member?
Delayed replica set member is a node that runs N number of seconds behind from the primary node. For example, if you have configured delayed node with one hour delay it will be always 60 minutes behind from the primary node. It means if you have created a new collection on the primary node it will appear in delayed node after 60 minutes.

Why Do we need a delayed replica set member?

We configure delayed node for the following purposes:

Safeguard the data from human mistakes like wrong code push on the primary. Accidental data insert or update.
For backup and recovery purposes when you get a lot of concurrent data changes happen from the primary. At any given point in if you have to revert any specific data set.
It can be used for a point in time recovery.
It can also be used while making BCP (Bussines Continuity Plan) setup.

How to configure it?

From primary node while adding a new delayed node just add β€˜cfg.members[0].slaveDelay = 3600’ where 3600 demotes the seconds.

Full command

cfg = rs.conf() Start the confiuration
cfg.members[0].priority = 0 Seting the node priority so that it never become primary

cfg.members[0].hidden = true It Can’t vote in node eletion process
cfg.members[0].slaveDelay = 3600 Delay in seconds
rs.reconfig(cfg) Save the configuration
Important Note:

There might be a slight disconnection because β€˜rs.config()’ may step down the primary and begin the node election process. You will see 5 to 10 seconds disconnect because this process will close all the application connection. The safer side you can perform delayed node addition in the downtime window.

read more:https://www.thedbadmin.com/delayed-replica-set-member-in-mongodb/

Top comments (0)

We want your help! Become a Tag Moderator.
Check out this survey and help us moderate our community by becoming a tag moderator here at DEV.