NOTE
3.1 Distributed Consensus Algorithm: Paxos
Paxos is a distributed consensus algorithm proposed by Lamport. These notes cover its roles and execution process through the problem of reaching agreement among nodes.
This is a historical learning note and may contain outdated or incomplete understanding.
1. Basic Paxos
1.1. What Is Basic Paxos?
- Abbreviated as Paxos.
- A distributed consensus algorithm invented by Lamport and the foundation of Raft and ZAB.
1.2. Basic Paxos Algorithm Process
1.2.1. Roles
- client: initiates requests; plays a peripheral role in this discussion.
- proposer: puts forward proposals, similar to a coordinator.
- acceptor: votes on proposals, similar to a participant.
- learner: learns proposals; plays a peripheral role in this discussion.
1.2.2. Two Phases
1.2.2.1. Prepare Phase
- The proposer puts forward a proposal numbered N and sends it to all acceptors.
- After each acceptor receives the number, it compares it with its saved maximum number maxN.
- If N < maxN, reject it.
- If N > maxN, update maxN to N and return (acceptorId, maxN, proposal content) to the proposer.
1.2.2.2. Accept Phase
- If proposal N receives responses from half of the acceptors during the prepare phase, the proposer sends the actual proposal content to the acceptors.
- After an acceptor receives the proposal, it checks whether the proposal number is greater than its own. If yes, it returns ok; otherwise, it rejects it.
- After the proposer receives confirmations from half of the acceptors, it succeeds; otherwise, it increments the proposal number and continues with the prepare phase.
1.2.3. Example
- Suppose there are three proposers and three acceptors. The leader-election phase is as follows:

1.3. Problems with Basic Paxos
1.3.1. Livelock
- Basic Paxos is a continuously looping 2PC. Therefore, if multiple clients write to multiple machines and every machine is a Proposer, conflicts between concurrent requests will be frequent. In other words, each node may need to execute multiple loops before a single log entry can be agreed on.
1.3.2. Performance
- Confirming one log entry requires at least two RTTs + two disk writes (one for the Prepare broadcast and reply, and one for the Accept broadcast and reply).
2. Multi Paxos
2.1. What Is Multi Paxos?
- It introduces the concept of a Leader, and all requests go through that Leader.
2.2. Why Is Multi Paxos Needed?
- It solves the livelock and performance problems of Basic Paxos.
- Livelock: change multiple writers into a single writer. Elect one Leader and allow only the Leader to act as the Proposer. When other machines receive write requests, they forward the requests to the Leader; alternatively, clients send all write requests to the Leader.
- Performance: change multiple writers into a single writer by electing one Leader.
3. Fast Paxos
4. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub