Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongodb

The mongodb documentation suggests that a replica set should have an odd number of voting nodes. What is the reason for this?

like image 502
S-K' Avatar asked Apr 22 '13 15:04

S-K'


1 Answers

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).

like image 154
Sergio Tulentsev Avatar answered Oct 08 '22 00:10

Sergio Tulentsev