Replica Set Configuration Questions

I have 2 questions when it comes to creating replica sets with Mongo DB. The questions are as follows:

  1. When creating a replica set do the secondary nodes have to be other computers? Let’s say with a replica set of 3 can all the members be from a single computer with different port numbers and DB paths assigned?
  2. Can the replica set members exist within different networks? Although I believe this might not be the best practice as the network delays are more prone to cause errors can this be done?

The answer to your first question is, yes all nodes can be on the same machine. I do this all the time for testing purposes and have had a 15 node cluster running locally on my MacBook. This is not recommended however as the instances will be fighting for the same resources and performance will suffer. The other problem with this is that if the machine dies, then you’ve lost access to your entire database.

The answer to your second question is yes as well. You just need to make sure that the proper firewall rules are in place to allow connections between the instances. As you mention, network latency comes into play here. Best practice is to have your instances placed in different data centers/network routes so it’s less likely that all instances are impacted by an outage in one location.


Thanks for the answers. They were in good detail and simple.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.