Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Replication is the distribution and maintenance of a live database server across multiple machines. MongoDB provides two flavors of replication: master-slave replication and replica sets. For both, a single primary node receives all writes, and then all secondary nodes read and apply those writes to themselves asynchronously.
Master-slave replication and replica sets use the same replication mechanism, but replica sets additionally ensure automated failover: if the primary node goes offline for any reason, then one of the secondary nodes will automatically be promoted to primary, if possible. Replica sets provide other enhancements too, such as easier recovery and more sophistical deployment topologies. For these reasons, there are now few compelling reasons to use simple master-slave replication.[1] Replica sets are thus the recommend replication strategy for production deployments; consequently, I’ll devote the bulk of this chapter to explanations and examples of replica sets, with only a brief overview of master-slave replication.
[1] The only time you should opt for MongoDB’s master-slave replication is when you’d require more than 11 slave nodes, since a replica set can have no more than 12 members.