Hi everyone and thanks in advance for the help. Let me briefly explain the problem: I need to implement a software module that runs in an HA environment on two server machines for an aerospace project. So, I have a cluster of only two machines under Docker Swarm. In this cluster, a single stack is executed with 5 services, and for the context, I chose MongoDB. I am asking for your help to understand the best strategy to install an instance of MongoDB that allows me to have consistent data on both machines and to be tolerant to the failure of one server. I have no possibility to expand the number of machines.
- Consistent data across two machines
- A normal MongoDB replica set will do this for you, for replica sets the minimum configuration and it’s best to do Primary, Secondary, Secondary. You can read/write to the Primary and Read from the secondary (if you want and your app can afford possible stale data based on replication time).
- Tolerant to failure of one server
- This isn’t possible (at minimum you need 3 which I know you can’t add), replica sets are deployed in odd numbers, so one of the nodes is going to have the majority of MongoDB processes on it so if it goes down your cluster will be READ only. Deploying in even numbers (not recommended) would also have the same issue, if a server goes down you don’t have a majority of processes up.
Server 1 has Primary, Secondary
Server 2 has Secondary
If server 1 goes down the cluster is read only because there will be no primary
If server 2 goes down the cluster will be health and R/W is possible.
Another example of 5 node replica
Server 1 Primary, Secondary, Secondary
Server 2 Secondary, Secondary
Again if Sever 1 goes down you have the same issue.