Replication related doubts

Q1. Replication can be done between two different serversor it can be done within the same server as well?
I understand that there wont be any purpose, but just for general query?

Q2. Does the election process starts after primary goes down, or it is done in advance while the primary server is up so as to save time when primary goes down,? During failover if any data that is about to be written in primary, how it gets written in secondary with 0 inconsistency, there must be some data loss?

Q3. If we have Server say 1, 2, 3, 4 where server 1 is primary, and if server 1 , 2 goes down then as per Tutorial, the remaining servers wont be able to elect a primary among themselves, so does that mean the availability fails even when we have two servers up and running, and why there cannot be election if server counts are even, in this case the remaining two server one must become P and another S and then when P fails the s must become P, why not?

So as per above explanation Suppose we have 5 server 1 2 3 4 5 and 1 being primary, if it goes down we are left with 4 servers and in this as well election cannot happen as two may vote for server 2 as primary and two may vote for server 3 as primary as per logic given in Tutorial?

Hi @Niket_Agrawal

Interesting topic. IMHO, it’d be better to split it into different posts.

Many of those questions are addressed in m103 or provide the user the tools to solve it, or to scope them to a specific problem.

Q1
I don’t know an exact answer for Q1 but since we can’t pass 2 dbPath to a mongod, we can conclude it’s not possible. Replication requires more than a single instance.

Q2
Reformulation: How do servers in replica set mode communicate to each other?
They ping each other (heartbeats), every 2ms (default). And an election is triggered by a secondary after 10ms without response.

Useful Links


I recommend to scope Q3 a bit, and maybe ask on a different thread, or await another reply.

Hi @Niket_Agrawal,

Either approach works.

Election can be triggered in response to a number of events. It only happens after the primary has stepped down(in case of replSetStepDown command) or is not available.

No data gets written to Secondary when Primary is not available. Secondary node receive data only through replication. All writes to the database happen only after a Primary node has been elected.

Some of your assumption are wrong regarding how voting works and what happens in case of even number of voting members are present. I would recommend you to go through the lecture videos again.

Please go through our documentation as well and let me know if something is not clear.

~ Shubham