- Frequently Asked Questions >
- FAQ: Replication and Replica Sets
FAQ: Replication and Replica Sets¶
On this page
- What kinds of replication does MongoDB support?
- What does the term “primary” mean?
- What does the term “secondary” mean?
- How long does replica set failover take?
- Does replication work over the Internet and WAN connections?
- Can MongoDB replicate over a “noisy” connection?
- Why use journaling if replication already provides data redundancy?
- How many arbiters do replica sets need?
- What information do arbiters exchange with the rest of the replica set?
- Which members of a replica set vote in elections?
- Do hidden members vote in replica set elections?
- Is it normal for replica set members to use different amounts of disk space?
This document answers common questions about database replication in MongoDB.
What kinds of replication does MongoDB support?¶
MongoDB supports replica sets.
Changed in version 3.0.0: In MongoDB 3.0.0, replica sets can have up to 50 nodes. Previous versions limited the maximum number of replica set members to 12.
MongoDB also supports master-slave replication; however, replica sets are the recommended replication topology. However, if your deployment requires more than 50 nodes, you must use master/slave replication.
What does the term “primary” mean?¶
|||In some circumstances, two nodes in a replica set
may transiently believe that they are the primary, but at most, only
one of them will be able to complete writes with |
How long does replica set failover take?¶
It varies, but a replica set will select a new primary within a minute.
The election itself may take another 10-30 seconds.
Does replication work over the Internet and WAN connections?¶
Can MongoDB replicate over a “noisy” connection?¶
Yes, but not without connection failures and the obvious latency.
Members of the set will attempt to reconnect to the other members of the set in response to networking flaps. This does not require administrator intervention. However, if the network connections among the nodes in the replica set are very slow, it might not be possible for the members of the node to keep up with the replication.
Why use journaling if replication already provides data redundancy?¶
Journaling is particularly useful for protection against power failures, especially if your replica set resides in a single data center or power circuit.
Journaling requires some resource overhead for write operations. Journaling has no effect on read performance, however.
Journaling is enabled by default on all 64-bit builds of MongoDB v2.0 and greater.
How many arbiters do replica sets need?¶
Replica sets require a majority of the remaining nodes present to elect a primary. Arbiters allow you to construct this majority without the overhead of adding replicating nodes to the system.
There are many possible replica set architectures.
A replica set with an odd number of voting nodes does not need an arbiter.
A common configuration consists of two replicating nodes that include a primary and a secondary, as well as an arbiter for the third node. This configuration makes it possible for the set to elect a primary in the event of failure, without requiring three replicating nodes.
You may also consider adding an arbiter to a set if it has an equal number of nodes in two facilities and network partitions between the facilities are possible. In these cases, the arbiter will break the tie between the two facilities and allow the set to elect a new primary.
What information do arbiters exchange with the rest of the replica set?¶
Arbiters never receive the contents of a collection but do exchange the following data with the rest of the replica set:
- Credentials used to authenticate the arbiter with the replica set. All MongoDB processes within a replica set use keyfiles. These exchanges are encrypted.
- Replica set configuration data and voting data. This information is not encrypted. Only credential exchanges are encrypted.
If your MongoDB deployment uses TLS/SSL, then all communications between arbiters and the other members of the replica set are secure. See the documentation for Configure mongod and mongos for TLS/SSL for more information. Run all arbiters on secure networks, as with all MongoDB components.
The overview of Arbiter Members of Replica Sets.
Which members of a replica set vote in elections?¶
All members of a replica set, unless the value of
votes is equal to
0, vote in
elections. This includes all delayed, hidden and secondary-only members.
Arbiters always vote in elections and
state of the voting
members also determine whether the member can vote. Only voting members
in the following states are eligible to vote:
Is it normal for replica set members to use different amounts of disk space?¶
Factors including: different oplog sizes, different levels of storage fragmentation, and MongoDB’s data file pre-allocation can lead to some variation in storage utilization between nodes. Storage use disparities will be most pronounced when you add members at different times.