Replication, Consensus, And Failover
Asked of: Software Engineer
Last updated

What's being tested
This topic tests whether you can reason about distributed state when machines fail, messages are delayed, and network partitions make healthy nodes appear dead. You should distinguish replication from consensus: copying data improves availability and durability, while consensus coordinates multiple nodes on one safe ordering of decisions. Meta cares because production services must preserve correctness under regional failures without turning every failover into data loss, split-brain writes, or a prolonged outage.
Core knowledge
-
Synchronous versus asynchronous replication defines the durability boundary. Synchronous followers acknowledge before a write completes, reducing potential loss but increasing
p99latency and reducing availability; asynchronous followers improve throughput but permit an acknowledged write to disappear during failover. -
Replication factor is the number of copies; quorum protocols commonly require write quorum and read quorum , with and often . This overlap helps reads observe writes, but quorum arithmetic alone does not guarantee linearizability.
-
Linearizability makes each operation appear to take effect atomically between invocation and response. Sequential consistency preserves a single global order but may violate real-time ordering; eventual consistency permits temporary divergence and requires application-level conflict resolution.
-
Consensus algorithms such as
RaftandPaxoschoose one ordered log despite failures.Raftseparates leader election, log replication, and commitment; a command is committed only after replication to a majority, preventing a minority partition from safely advancing state. -
Terms, epochs, and fencing tokens prevent stale leaders from writing after a delayed network path recovers. Every request should carry the current generation or lease token, and storage must reject operations from an older token rather than trusting the client’s view.
-
Leader election requires a failure detector, usually timeouts and randomized backoff. A timeout is only suspicion, not proof: GC pauses, overload, or packet loss can create false failovers, so systems need quorum checks and term validation to avoid split brain.
-
Failover correctness has three separate goals: availability, bounded data loss, and bounded recovery time. State them as
RTO(how quickly service returns),RPO(how much acknowledged or recent data may be lost), and the consistency guarantee users receive during recovery. -
Write-ahead logs and state-machine replication make recovery deterministic. Nodes persist log entries before applying them, replay committed entries after restart, and use snapshots or checkpoints to avoid replaying an unbounded history; truncation must preserve entries needed by lagging replicas.
-
Read behavior during failover must be explicit. A stale replica may serve availability-oriented reads, while a linearizable read must contact the current leader or establish a quorum; session guarantees such as read-your-writes may require session metadata or routing affinity.
-
Network partitions expose the
CAPtradeoff: when communication is interrupted, a system cannot simultaneously guarantee availability for every partition and linearizable consistency. A well-designed answer identifies which operations reject, which may proceed, and how reconciliation works afterward.
Worked example
Representative question: “Design a replicated key-value store with automatic failover.”
In the first 30 seconds, clarify the consistency target, write/read workload, replication factor, regional topology, acceptable RPO/RTO, and whether overwrites or transactions are required. I would organize the answer around four pillars: the replicated log and storage format, leader election and consensus, client routing and failover, and monitoring plus recovery. I would choose a Raft-like leader for a shard, persist commands in a WAL, replicate them to a majority, and apply only committed entries to the state machine. Reads would either go through the leader for linearizability or use followers only when bounded staleness is acceptable. The key tradeoff is whether to acknowledge after one durable replica or after a majority: the former lowers latency but increases failover data loss, while the latter sacrifices availability when a quorum is unavailable. I would explicitly address stale leaders using terms and fencing tokens, rather than assuming a timeout proves failure. I would close by saying that, with more time, I would detail shard rebalancing, snapshot installation, rolling upgrades, and fault-injection tests for partitions and delayed messages.
A second angle
A different framing is cross-region database failover, where latency and correlated regional failures dominate the design. Instead of assuming a majority is nearby, compare single-region consensus with synchronously replicated regions and asynchronous disaster-recovery replicas. The central question becomes whether the business prefers a higher RPO with fast regional writes or a lower RPO with cross-region commit latency and reduced availability during a partition. You should also explain DNS or service-discovery convergence, promotion safety, and how the old region is fenced before the new region accepts writes. This demonstrates that failover is both a protocol problem and an operational sequencing problem.
Common pitfalls
Pitfall: Treating replication as consensus. Saying “three replicas means the data is safe” is incomplete; without an agreed leader, commit rule, and stale-writer fencing, replicas can diverge or accept conflicting writes.
A common analytical mistake is claiming that W + R > N automatically provides strong consistency. That condition creates quorum overlap under a specific protocol, but linearizability also requires correct leader behavior, version ordering, durable commit rules, and protection against concurrent writes.
A communication mistake is jumping directly to Raft without stating requirements. Start with consistency, availability, RPO, RTO, and failure assumptions; then justify the protocol and acknowledge what the design deliberately gives up.
A depth mistake is describing election but not recovery. Strong answers explain how a new leader identifies committed versus uncommitted entries, catches up lagging replicas, handles snapshots, fences the old leader, and avoids serving acknowledged-but-lost data.
Connections
The interviewer may pivot to CAP, linearizability, idempotency, exactly-once effects, distributed transactions, or shard rebalancing. Be ready to connect failover with observability: leader changes, replication lag, quorum health, rejected stale-epoch requests, and recovery duration are essential correctness signals.
Further reading
- In Search of an Understandable Consensus Algorithm (
Raft) — the clearest practical treatment of leader election, replicated logs, commitment, and safety. - Paxos Made Simple — concise explanation of consensus safety and quorum-based agreement.
- Designing Data-Intensive Applications — accessible coverage of replication, consistency models, partitions, transactions, and distributed-system tradeoffs.
Related concepts
- Distributed Storage, Replication, and ConsistencySystem Design
- Distributed Systems Reliability For Rippling Services
- Distributed Storage Architecture
- Distributed Systems Reliability And ConcurrencySystem Design
- Distributed Systems Consistency, Reliability, And ObservabilitySystem Design
- Distributed Systems Correctness And IdempotencySystem Design