Replication and leader election
Keep the same log on several machines, let one of them lead, and decide how many copies must exist before anyone hears yes. The term on every write is what stops a replaced leader from doing damage.
Does adding read replicas make writes faster?
No. Every write still goes through the one leader, and every replica has to apply every write too, so adding followers adds work per write rather than removing it. Replicas multiply read capacity and give you a spare to fail over to. If writes are the bottleneck, the answer is to split the data across leaders by key, which is partitioning.
What is the difference between synchronous and asynchronous replication?
It is a question of when the client hears yes. Asynchronous replication says yes as soon as the leader has the write and copies it afterwards, so a leader that dies in that gap takes the write with it. Synchronous replication waits for followers first, which costs a round trip and a disk flush on each write. The usual middle ground is to wait for a majority, so one slow or dead follower does not stall writes.
Why does a replication group need an odd number of nodes?
Because decisions are made by a strict majority, and a fourth node adds cost without adding tolerance. Three nodes have a majority of two and survive one failure. Four nodes need three to agree, so they also survive only one failure. Five nodes need three and survive two, which is why real clusters come in threes and fives.
What is a fencing token?
It is a number that grows each time leadership changes, attached to every write the leader sends. Anything that stores data remembers the highest token it has accepted and refuses a write carrying a lower one. A leader that paused for a long garbage collection and woke up after being replaced still believes it leads, but its writes carry the old token and are refused. In this block the token is the term.
How do I read my own write from a replica that lags?
Remember the log position your write ended at, and read only from a replica that has applied at least that far. If none has, read from the leader. This gives read-your-writes consistency without sending every read to the leader, and it is the follow-up interviewers ask most often once you mention read replicas.