Why does a mongodb replica set require an odd number of voting nodes?

Let's imagine that a replica set has even number of nodes (4, for example). Then an unfortunate network partition happens that splits the set in half (2 + 2). Which partition should accept writes? First? Second? Both? What should happen when network is restored? These are all hard questions.

Having odd number of nodes eliminates the questions entirely. The set can't be split exactly in half. So the bigger part will accept writes (to be exact, node must see more than half of nodes (including self) to be elected as primary. So it's 1 of 1, 2 of 3, 3 of 5, 4 of 7 and so on).

Tags:

Mongodb