Mongodb – How to MongoDB elect a new primary when a datacenter has failed

failoverhigh-availabilitymongodbreplication

I am curious about the following situation when setting up a MongoDB cluster.

2 Datacenters, 2 nodes in each data center for a total of a 4 node replicaset. One of the two datacenters has become unavailable for any reason, thus blacking out the primary and one of the secondaries.

Per fault tolerance section of https://docs.mongodb.com/manual/core/replica-set-architectures/: I need at minimum 3 votes to elect a new primary, but will only have 2 surviving voters.

I am unable to extend into a 3rd datacenter.

How can I setup the cluster to be able to withstand a datacenter failure and continue to write in the surviving datacenter?

Best Answer

You need another replica set member (or arbiter) in a 3rd data center. But if you cannot extend to a 3rd center, then add the 5th member of the replica set to your main data center. Your backup data center will remain with two members.

If backup data center goes down, main center will stay up and replica set operations will continue.

If main center goes down, replica set operations will be read only and you will need to perform manual intervention.

References:

Deploy a Geographically Redundant Replica Set

Replica Sets Distributed Across Two or More Data Centers