Case Study

MongoDb Replication & Failover & Sharding


We are implenting load balancing and fail over product having a lot trafic. We have setup load balancing for out node.js application (by adding two different Primary & Secondary server), but what about database? how to implement load balancing into mongodb? because we can't setup two seprate DB in two different application server (Primary & seconday). Our main concern is that we should have to use same db in both server. so to overcome this problem we find out two solutions,
1. Centralise database
2. Replication
After some reserch we decided to go with mongodb relpication to overcome this problem. reason behind to use replication is we will have two copy of dbs. so in case of one database fail or not able to respond second database will always there to respond, so we can add failover too


Replication means we are creating second mongod process and another copy of database. Terminology for this is replica set. Best practise is you should have to create 3 or more replca sets, but in our case we have created only two replica set one is Primary and other one is secondary and one Arbitary(to manage Heart bit). MongoDB replication is very usefull and easy to use in some simple step. Click here to know more about mongodb replication, Later we have added sharding too.