What are reasons to choose a replica set over master-slave replication?
2 Answers
In addition to providing all the functionality of master-slave deployments, replica sets are also more robust for production use.
Master-slave replication preceded replica sets and made it possible to have a large number of non-master (i.e. slave) nodes, as well as to restrict replicated operations to only a single database; however, master-slave replication provides less redundancy and does not automate fail over.
Question 1:
Why you should use replica set over master-slave replication?
Answer:
A) Automated handling of failures - In situations where the master node has failed in the Master-Slave replication you would have to perform manual actions like connecting to one of the slaves and restart it as a master.
Replica-set provides this out of the box and one of the secondaries will be automatically elected as a new primary.
B) Automated Recovery - In the Master-Slave replication the oplog exist only on the master so in case of failures you would have to re-create it on the new master and then sync all other slaves to it.
Replica-set handle oplogs differently and save you this extra administration effort.
Question 2:
When to use each one of the deployment strategies?
Answer:
When you can.
Replica-Set can be considered as the next-generation of Master-Slave strategy so it should provide you with all the capabilities that the old Master-Slave architecture gave.
With addition to that, since MongoDB 3.6 master-slave replication is deprecated.
The only situation where I can think of that Master-Slave is preferred (beside when running on legacy systems) is when you have more then 50 replica nodes in the architecture - This is the top limit of Replica Set at least as mentioned here.