• Webinar: Multi-Data Center Deployment 8 

## 9.2.3 Replica Set High Availability 

Replica sets provide high availability using automatic failover . Failover allows a secondary member to become pri- mary if primary is unavailable. Failover, in most situations does not require manual intervention. 

Replica set members keep the same data set but are otherwise independent. If the primary becomes unavailable, the replica set holds an election (page 580) to select a new primary. In some situations, the failover process may require a rollback (page 584). 9 

The deployment of a replica set affects the outcome of failover situations. To support effective failover, ensure that one facility can elect a primary if needed. Choose the facility that hosts the core application systems to host the majority of the replica set. Place a majority of voting members and all the members that can become primary in this facility. Otherwise, network partitions could prevent the set from being able to form a majority. 

## Failover Processes 

The replica set recovers from the loss of a primary by holding an election. Consider the following: 

Replica Set Elections (page 580) Elections occur when the primary becomes unavailable and the replica set members autonomously select a new primary. 

Rollbacks During Replica Set Failover (page 584) A rollback reverts write operations on a former primary when the member rejoins the replica set after a failover. 

## Replica Set Elections 

Replica sets use elections to determine which set member will become primary . Elections occur after initiating a replica set, and also any time the primary becomes unavailable. The primary is the only member in the set that can accept write operations. If a primary becomes unavailable, elections allow the set to recover normal operations without manual intervention. Elections are part of the failover process (page 580). 

In the following three-member replica set, the primary is unavailable. The remaining secondaries hold an election to choose a new primary. 

Behavior Elections are essential for independent operation of a replica set; however, elections take time to complete. While an election is in process, the replica set has no primary and cannot accept writes and all remaining members become read-only. MongoDB avoids elections unless necessary. 

If a majority of the replica set is inaccessible or unavailable, the replica set cannot accept writes and all remaining members become read-only. 

## Factors and Conditions that Affect Elections 

Heartbeats Replica set members send heartbeats (pings) to each other every two seconds. If a heartbeat does not return within 10 seconds, the other members mark the delinquent member as inaccessible. 

