Does every server in a MongoDB replica set need to have exactly the same RAM? Does every server in a MongoDB replica set need to have exactly the same RAM? mongodb mongodb

Does every server in a MongoDB replica set need to have exactly the same RAM?


No, you do not need equal RAM. (Yes, you could set up a replica set as described.)

MongoDB uses memory-mapped files for all caching, which means that cache paging is handled by the operating system. The replicas with more memory will keep more of the database in memory; those with less will page more to disk.

MongoDB will eventually bring the entire database into memory if it can. If you're using two replicas for reads and one for writes, you might want to use the 5gb and 4gb machines for reads, so they are more likely to be hitting RAM.


Yes, you can configure a replica set this way.

If yes, what are the pros and cons?

Here's a doc explaining the major features of replica sets. Let's take a look at these in light of the RAM differences.

Pros:

  • More computers means better data redundancy. Having that 2GB node at least means that you have one more copy of the data.
  • Having a full 3 nodes on a replica set makes it easier to take one down for maintenance.

Cons:

  • Having servers of different sizes isn't great for automated failover. Let's say that your 5GB server is the primary. What happens when it goes down and the 2GB server wins the election? You still have automated fail-over, but your performance has probably dropped dramatically.
  • Read scaling may not work very well. Depending on your read patterns, sending reads to the 2GB server may result in lots of extra disk hits and slower performance.

So, the big problem here, is really one of performance. If you're just doing this for a dev setup, then it will basically work. But in production you run the risk of completely tanking your app. If your app is used to living on 4GB+ of RAM and then suddenly drops to 2GB, it may become unusable.

Most production setups want to fail over to another "equally-powered" computer.