I've got a question concerning multiple masters in a replicaSet with MongoDB. I have the following layout:
Server A --> with MongoDB & several applications
Server B --> with MongoDB & several applications
Both instances of MongoDB are organised in the same replica Set (Server A as Primary, Server B as Secondary). But now there is the problem. Both databases should contain data from the applications on the server.
Is it possible to deploy a replica Set with two masters so that the data from Server A is available in MongoDB at Server B and vice versa?
Thank you very much in advance
MongoDB does replica sets and sharding. As far as I know it doesn't support multi-master architectures or data syncing. Even the Atlas-style global data distribution is sharding, right?
A replica set can have up to 50 members but only 7 voting members.
I am aware that mongodb has a master-slave architecture. Therefore, I was thinking that the master would be the single point of failure in mongoDB since it takes care of all the requests and sends it to the slave nodes. However, when the master fails, then a new master is reelected from the slaves.
What kind of replication does MongoDB support? MongoDB supports replica sets, which can have up to 50 nodes.
Replica sets in MongoDB can only have a single master at this point. (It is called the primary of a replica set.) For your scenario, the solution is often to use a sharded cluster. In your example, you would have two shards: one for the data of server A, and the other for the data of server B. Both shards are implemented as replica sets, so each has a minimum of three servers. You would then put the primary of the A shard in the same data center A, and the primary of the B shard in data center B. At least one replica of each shard (called a secondary) would be located in the other data center.
This means that all the data is available in each data center, but writes to the A shard always need to happen in data center A, and writes to the B shard in data center B. (Although writes can also be done remotely, so you can write to shard A from data center B, it's just that it's a remote write in this case.)
No MongoDB is single master only.
The only way to create two separate replicas like this currently while keeping them in sync is to do it manually but that is not advised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With