software-engineer-blog logoSoftware Engineer Blog

Module 8 · Distributed systems

Unit 28 of 49

Unit 28 · Module 8 · Distributed systems

Replication

One copy is a single point of failure; more copies means lag.

Unit 28 of the free 49-unit computer-science course, in distributed systems. 3 topics to watch or read, 3 interview questions answered in full and a short self-check.

Watch or read

3 topics make up this unit. Take each one whichever way suits you, then answer the questions below.

Active-active vs active-passive

You own two machines. Only one of these two designs is actually using the second one. Active-passive keeps a standby in sync and promotes it when the primary dies; active-active runs both live, all the time. Here's what each one looks like in code, the four steps of a failover and what they cost, the conflicts and split brain that active-active hands you instead, and why the honest answer is usually both — at different layers of the same system.

ReelRead

Interview questions this unit unlocks

Asked out loud, answered out loud. Read the answer, then say it in your own words.

Synchronous or asynchronous replication — which do you pick?

It is a choice about what you are willing to lose. Synchronous means the primary waits for a replica to confirm before acknowledging the write, so a failover loses nothing — and every write now pays a network round trip, and a slow replica slows the primary. Asynchronous acknowledges immediately and ships the change after, so writes stay fast and a failover can lose the last few seconds. Ask what the data is before answering: payments and session state have very different answers.

The middle ground worth naming: acknowledge when any one of N replicas confirms, which bounds the loss without waiting for the slowest.

You added a second server and were still down for 41 minutes. Why?

Because a standby is not a failover. Active-passive gives you a machine with the data and nothing that promotes it — someone has to notice, decide, promote the replica, repoint the application and drain stale connections, and every one of those minutes is downtime. Active-active takes traffic on both from the start, so the failure mode is capacity loss rather than an outage — at the cost of having to resolve conflicting writes.

The number to give: your recovery time is not the replication lag, it is detection plus decision plus promotion plus DNS or connection draining.

What is replication lag and what breaks because of it?

The delay between a write landing on the primary and appearing on a replica. It breaks read-your-own-writes: a user updates their profile, the next request is served by a lagging replica, and their change is gone. The fixes are routing a user to the primary for a short window after they write, or pinning them to one replica, or carrying the write position in the session and waiting for the replica to catch up.

Self-check — 3 questions

Answer alone, at 2am, with no interviewer in the room.

Part of Everything You Need to Know About Computer Science.