MongoDB – Setup Replica Servers with Different Power Configurations

clusteringconfigurationmongodb

Is it a good practice to setup replicas with the same machine size (wrt. CPUs, RAM, Bandwidth, etc.) or can replicas be based on smaller machines? One usecase might be to have a small non-voting backup replica machine. Another is to save money on the replica "backend".

The only problem I see with voting replicas is that in case the primary (big machine) goes down the new primary would be weaker. Are there other problems with clusters using different machine sizes?

Best Answer

You can use machines of different sizes as long as the lesser machines can actually keep up with the more capable primary when replicating (particularly at peak traffic times). You can use priorities to ensure that the more powerful machines are preferred when they are up and healthy and you can set any host that absolutely should not become primary to priority 0. Caveats:

  • Do not mess around with votes unless absolutely necessary
  • Always keep the number of voting members to an odd number
  • If the only node left healthy in the set is priority 0 it will stay secondary (no primary, no writes)

One other note - if (for example) the nodes fall behind at peak, but catch up later that is usable but you will want to make sure your oplog window is big enough to cover the lag and you may want to make the lagging nodes hidden so that secondary reads do not see a lagging version of the data. Similarly, if you are seeing lag you will need to be careful with write concerns that require replication (w:2 for example) since they might end up requiring the lagging node to catch up to satisfy the concern and return successfully.

To summarize: yes you can do this, but you need to be aware of the possible implications of doing so and it can potentially complicate your deployment (versus homogeneous hosts).