Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Multiple Masters in ReplicaSet

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

like image 384
DanielH Avatar asked Apr 10 '14 12:04

DanielH


People also ask

Does MongoDB support multi master?

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?

What is the maximum number of member instances a replica set can have in MongoDB replication before version 3.0 0?

A replica set can have up to 50 members but only 7 voting members.

Is MongoDB single master?

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 is the maximum number of nodes in a MongoDB replica set?

What kind of replication does MongoDB support? MongoDB supports replica sets, which can have up to 50 nodes.


2 Answers

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

like image 86
drmirror Avatar answered Oct 10 '22 03:10

drmirror


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.

like image 25
Sammaye Avatar answered Oct 10 '22 03:10

Sammaye