Reputation: 51
I'm new to MongoDB correct me if I'm wrong. In MongoDB read and write operation is performed on the primary node. Doesn't it makes more sense to do a read operation in both primary and secondary while write operation only in primary node. As the primary node will eventually update the secondary nodes. If both read and write operation has to be done from primary node then why to maintain more than one secondary node as it will not reduce the traffic to a single database, ignoring the data safety part for time being.
Upvotes: 1
Views: 84
Reputation: 982
By default, the Primary handled both read and write but you can direct your reads to Secondary nodes and mongodb supports that. The question is, are you ok with reading stale data. Because the Secondary nodes replicate by tailing the Primary's oplog, they usually lag behind the Primary and you may end up reading old data at times. If your requirement isn't realtime read/write, it is totally fine to read the data from Secondary nodes
The main purpose of maintaining more than one secondary node is also for High Availability (no downtime). For instance, if you've a 3 node replica set and say one node is down due to NW issue. At this state, you have two nodes (majority members) online that can serve the read and write requests without any impact to your application
Upvotes: 1