Chapter 8. Replication

 

In this chapter

  • Basic replication concepts
  • Administering replica sets and handling failover
  • Replica set connections, write concern, read scaling, and tagging

Replication is central to most database management systems because of one inevitable fact: failures happen. If you want your live production data to be available even after a failure, you need to be sure that your production databases are available on more than one machine. Replication ensures against failure, providing high availability and disaster recovery.

I begin this chapter by introducing replication in general and discussing its main use cases. I’ll then cover MongoDB’s replication through a detailed study of replica sets. Finally, I’ll describe how to connect to replicated MongoDB clusters using the drivers, how to use write concern, and how to load balance reads across replicas.

8.1. Replication overview

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.

8.2. Replica sets

8.3. Master-slave replication

8.4. Drivers and replication

8.5. Summary