Part 4 · Blueprint 17
Distributed Consensus: Raft & Multi-Paxos
15 min reading · Sources · Editorial review pending
Majority agreement has precise safety rules; a timeout alone does not prove the leader failed.
Page details
Published date · Last edited:
Draft edition. Editorial review and supplementary reading recommendations are still being completed.
Format: Architecture walkthrough. Prerequisites: the beginner bootcamp. Chapter prerequisites: Consistency Models: CAP, PACELC & Linearizability, Replication, Consensus & Automated Failover.
Sixty-second mental model
Problem: Majority agreement has precise safety rules; a timeout alone does not prove the leader failed.
Use: Separate commitment, application and client acknowledgment.
Design boundary: Use consensus to maintain one committed command history despite selected crash/partition failures. A leader is not authoritative merely because it is alive; commitment and membership rules establish which history can survive elections.
Layer 1 · Intuition
Hypothetical scenario: Northwind is designing consensus. Maya represents product requirements, Dev implementation and Priya reliability. The team must agree what one entry means and which component owns the committed log.
Think of a committee maintaining one official meeting journal. Separate the requester from committed log, then identify the retained evidence needed after failure.
- Authority
- The entitled state owner.
- Invariant
- A rule preserved across concurrency and failures.
- Consensus
- A protocol problem of reaching agreement among participants under specified failures. Analogy: A committee agreeing on one ordered official record.
- Follower
- A node following a leader's replication or coordination role in a protocol. Analogy: A clerk maintaining the chair's approved record.
- Leader
- A node holding a defined coordination or write role within a protocol. Analogy: The currently authorized meeting chair.
- Quorum
- A set of participants satisfying a protocol's required intersection or voting rule. Analogy: Enough authorized votes to meet a defined decision rule.
- Raft
- A replicated-log consensus protocol with leader election and log consistency rules. Analogy: An elected chair coordinating an agreed meeting journal.
Architecture and worked reasoning
Design boundary: Use consensus to maintain one committed command history despite selected crash/partition failures. A leader is not authoritative merely because it is alive; commitment and membership rules establish which history can survive elections.
Responsibilities on the request path
Workload and limiting resource
A hypothetical five-voter group needs a majority of three. It can form that majority after two unavailable voters, but not after three. This is a fault-count bound under the protocol model, not an uptime prediction. A network split of three and two permits progress only on the majority side when the required protocol conditions hold.
Keep the units attached to each intermediate result. The assumptions above describe a hypothetical exercise, not observed vendor capacity. A real capacity decision also needs a measured service curve, skew, recovery traffic and an explicit admission policy for overload.
Mutation or publication path
- Append under the current term and membership.
- Replicate and establish commitment according to the protocol.
- Apply committed entries in order and deduplicate client operations.
Observation and recovery path
- Use a protocol-supported current read.
- Do not equate an old leader lease with indefinite authority.
- Recover state from snapshot plus committed log suffix.
Failure that changes the decision
Hypothetical scenario: A paused former leader resumes after a replacement was elected. It must observe the higher term or be rejected; external effects also need an appropriate fence/identity boundary.
Attempt this decision before reading the explanation
Does a majority acknowledgement permit deleting every older log entry?
No. Snapshot state, lagging replicas, configuration changes and recovery all impose retention requirements. Compaction must preserve a complete recoverable committed state and required metadata.
Supporting mechanism analysis
Hypothetical scenario: Northwind. Maya represents product, Dev implementation and Priya reliability. The following workflow develops the underlying mechanism.
In short. Require a quorum-backed term before exercising leadership. Record the term that authorizes each coordinator.
Hypothetical scenario. A scheduled settlement job should have one active owner. The old worker pauses, another takes over, and the old worker resumes with its original credentials. Both now try to submit the settlement. A heartbeat dashboard cannot decide which action the receiving resource should accept.
Consensus establishes agreement among participating nodes under a specified failure model. In a replicated service it can maintain an ordered history of authority and state transitions. The practical question is which decision needs shared agreement and how the application enforces that decision beyond the coordination service.
If a worker stops responding, it may have crashed, paused or become unreachable through one path. Declaring it dead does not physically prevent it from running. Independent monitors can therefore elect different owners if they each treat local silence as conclusive authority.
Consensus protocols distinguish preserving a safe decision history from making progress. Under sufficiently poor communication, a system can preserve safety by refusing to decide. Availability depends on communication and surviving participants under the protocol's assumptions; no timeout setting removes that dependency.
Do not invent a leader election protocol from a shared timestamp and a periodic cleanup task. The application may need only a conditional change in an existing authoritative database. If it does need a replicated coordination service, use a documented, maintained implementation and understand its failure and recovery model.
A replicated state machine applies the same deterministic commands in the same agreed order. The log position identifies that order; the state machine defines what a command does. An application must make external inputs explicit rather than letting each replica independently read a different clock or external balance.
Hypothetical scenario. Take a fixed five-member group A, B, C, D and E. Every member has the same committed log through index 20, whose last entry has term 7. Leader A becomes unreachable. B, C and D can communicate; E is slow. These are chosen starting conditions, not a recorded outage.
C's election timer expires. It increments its term from 7 to 8, records its vote for itself and requests votes. B and D compare C's last-log term and index with their own. Here the logs are equally up to date, and neither has voted for another candidate in term 8. After persisting their term and vote, they grant C their votes. C has itself, B and D: three votes out of five, so it becomes leader in term 8.
Those votes choose a leader; they do not commit the settlement command. C first establishes contact as leader. A client then requests “assign settlement job to generation 42” under operation identity K. C durably appends that command at index 21 with term 8 and sends AppendEntries referring to predecessor index 20, term 7. B and D verify that predecessor, persist the new entry and acknowledge. C now knows that C, B and D hold index 21.
Because index 21 belongs to C's current term and is replicated to a majority, C advances its commit index to 21. It applies committed commands in order, recording the operation result. Later replication or heartbeat messages carry the advanced commit position so followers can apply it too. A follower holding the entry may therefore be behind in knowledge of commitment without holding different command bytes. These rules follow Raft, Figure 2 and Sections 5.2–5.4 .
Northwind's coordinators need an agreed order for assignments, not a vote about whether a network timeout proves a worker dead. In Raft, a term identifies an election generation. Voting constraints and the replicated log work together so a new leader preserves committed history. The majority calculation is part of that protocol, not a substitute for its log-matching and commitment rules.
For a fixed five-member group, three is a majority because floor(5 / 2) + 1 = 3. Any two groups of three overlap in at least one member. With durable voting and the protocol's other conditions, that overlap contributes to election safety. Two unavailable members leave three that can potentially communicate and progress; a partition that prevents those three from exchanging the required messages still prevents progress. Node count alone is not a latency or availability guarantee.
A leader replicates entries and advances commitment under Raft's rules before applying committed commands to its state machine. Receiving an entry is different from committing it, and committing a command is different from successfully carrying out an unrelated remote action. Keep external effects behind their own identity, authorization and reconciliation boundary. Consensus makes replicas agree on an invalid business rule just as effectively as on a valid one.
An old worker illustrates the last boundary. Suppose generation forty-two replaces generation forty-one. A protected resource must reject generation forty-one where the action is accepted, or another effective exclusion mechanism must do that job. Merely writing forty-two into a coordinator store does not stop the paused older process when it resumes. Use consensus for the narrow shared decision that needs ordering, and enforce the resulting authority at the resource it protects.
Hypothetical scenario. Choose a fixed five-member coordination group. A majority contains floor(5 ÷ 2) + 1 = 3 members. Two majorities have at least 3 + 3 − 5 = 1 member in common. If two members are unavailable, three remain; if three are unavailable, only two remain and cannot form this majority.
This demonstrates set intersection under fixed membership. It does not prove safety for an arbitrary voting implementation or establish progress during unbounded delays. Durable protocol state and valid transition rules still matter.
Now suppose the agreed authority generation changes from 41 to 42 when ownership moves. The protected resource has durably recorded 42. A resumed worker presents 41; checking 41 < 42 allows the resource to reject that obsolete action. A current worker presenting 42 must still pass authorization and business validation.
If the resource never checks the generation, recording 42 in the coordinator alone cannot stop the old worker's call. If independent resources each remember different generations, the application must define how authority reaches and is enforced by all required effect boundaries.
Layer 3 · Internals
Trade-offs and limits
| Approach | Provides | Requires |
|---|---|---|
| Leader-based replicated log | Gives accepted commands one protocol-defined order. | A leader transition and quorum loss affect progress. |
| Local independent state | Avoids consensus where operations truly do not share an invariant. | It cannot replace agreement when callers require one authoritative history. |
Recovery decision
Hypothetical scenario: A paused former leader resumes after a replacement was elected. It must observe the higher term or be rejected; external effects also need an appropriate fence/identity boundary.
No. Snapshot state, lagging replicas, configuration changes and recovery all impose retention requirements. Compaction must preserve a complete recoverable committed state and required metadata.
Write your design before revealing the review
Does a majority acknowledgement permit deleting every older log entry?
Drafts and self-review are stored only in this browser. They are separate from reading completion.
Compare your decision
No. Snapshot state, lagging replicas, configuration changes and recovery all impose retention requirements. Compaction must preserve a complete recoverable committed state and required metadata.
A paused former leader resumes after a replacement was elected. It must observe the higher term or be rejected; external effects also need an appropriate fence/identity boundary.
Check your understanding
Does a majority acknowledgement permit deleting every older log entry?
No. Snapshot state, lagging replicas, configuration changes and recovery all impose retention requirements. Compaction must preserve a complete recoverable committed state and required metadata.
How would you recover from this failure: A paused former leader resumes after a replacement was elected. It must observe the higher term or be rejected; external effects also need an appropriate fence/identity boundary.
Start with the exact boundary that failed. Append under the current term and membership. Replicate and establish commitment according to the protocol. Apply committed entries in order and deduplicate client operations. Then recover evidence through the observation path: Use a protocol-supported current read. Do not equate an old leader lease with indefinite authority. Recover state from snapshot plus committed log suffix. Preserve the distinction between a confirmed state change and an unavailable response.
Which assumption in the worked calculation would a burst or concentrated tenant invalidate first?
A hypothetical five-voter group needs a majority of three. It can form that majority after two unavailable voters, but not after three. This is a fault-count bound under the protocol model, not an uptime prediction. A network split of three and two permits progress only on the majority side when the required protocol conditions hold. Recompute the affected resource rather than multiplying unrelated storage and network budgets by the same factor. Use consensus to maintain one committed command history despite selected crash/partition failures. A leader is not authoritative merely because it is alive; commitment and membership rules establish which history can survive elections.
Which component in this topology could be removed from a smaller first deployment?
Client command, Leader log, Voter majority, State machine name responsibilities, not a requirement for separate processes. Co-locate responsibilities when their transaction, trust and capacity boundaries permit it. Append under the current term and membership.
What evidence must a caller have before relying on the observation path?
Use a protocol-supported current read. Do not equate an old leader lease with indefinite authority. Recover state from snapshot plus committed log suffix. No. Snapshot state, lagging replicas, configuration changes and recovery all impose retention requirements. Compaction must preserve a complete recoverable committed state and required metadata.
45-minute interview rubric
- 00–05: scope entry and committed log.
- 05–12: identify the limiting resource and derive the domain workload above, retaining units and assumptions.
- 12–28: draw committed log, numbered writes and reads.
- 28–40: challenge recovery: Separate commitment, application and client acknowledgment.
- 40–45: defend term placement, observations and remaining assumptions.
Go deeper
- etcd learner design | etcd · Primary document · etcd.io. Separate commitment, application and client acknowledgment. Verified 2026-10-26.
Decision log
Separate commitment, application and client acknowledgment.
Preserve entry identity and committed log ownership.
Revisit changed workload, observations or recovery objectives.