An architectural overview
MongoDB’s replication is illustrated in the following diagram:
Figure 13.1 – MongoDB replication conceptual architecture
The primary server is the only one that can take writes at any time. The secondary servers are in a hot standby state, ready to take over if the primary server fails. Once the primary server fails, an election takes place regarding which secondary server will become primary.
We can also have at most one arbiter node. An arbiter node does not hold any data, and its sole purpose is to participate in the election process.
We must always have an odd number of nodes (including the arbiter). Three, five, and seven are all fine so that in the event of the primary (or more servers) failing, we have a majority of votes in the election process.
When the other members of a replica set don’t hear from the primary for more than 10 seconds (configurable), an eligible secondary will start the election...