Mongodb Chained Vs Normal Replication
Mongodb provides replication to achieve the redundancy and increases data availability (high availability).
With multiple copies of data on different database servers, replication provides a level of fault tolerance against the loss of a single Mongodb database server.
Apart from redundancy and high availability, in some case it can provide increased read capacity (using read request distribution) too. You can direct your queries to a given secondary node too using tags. Tags are used to redirect the queries based on the use cases like all the analytical queries should go to the secondary node having “Analytics” tag, all the reads for the application should go to the secondary node having “App” tag etc.
Secondary nodes could be used for backup/disaster recovery purpose too.
Mongodb uses Oplog capped collection to perform the replication process. Each of the node has its own Oplog collection where each transaction is recorded with the timestamp. Replica set nodes have an OpObserver process that inserts a document to the oplog whenever a write/delete/update to the database happens, describing the write/delete/update. A secondary keeps its data synchronized with its sync source by fetching oplog entries from its sync source. This is done via the OplogFetcher.
There are two ways to replicate the data—
1> One of the secondaries pull the data from Primary Node and then rest of the secondaries pull the data from that secondary. This is called chained replication.
Chained replication should be used when you do not want to put all the replication loads the a single Node (Primary Node). So, in case of chained replication you distribute the loads. It can also result in increased replication lag. MongoDB enables chained replication by default. You can use the settings.chainingAllowed setting in Replica Set Configuration to disable or enable the chaining based on your requirements.
2> All the secondaries pull the data from the Primary Node
In this replication process all the secondaries get data from Primary Node. In this case all the read loads go to a single Node (Primary Node). This kind of replication process is a bit faster than chained replication process.
Enable Chained Replication-
cfg = rs.config()
cfg.settings.chainingAllowed = true
rs.reconfig(cfg)
Disable Chained Replication-
cfg = rs.config()
cfg.settings.chainingAllowed = false
rs.reconfig(cfg)
Once you enable or disable chaining, you can see the replica lag info using below command
db.printSlaveReplicationInfo()
If you want, you can change the SyncFrom for each secondary to modify the chaining order-
db.adminCommand( { replSetSyncFrom: "HostName:PortNo" })
https://dba.stackexchange.com/questions/295923/mongodb-chained-replication-related-questions