Paxos understanding
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Paxos is a consensus algorithm that's fundamental in the field of distributed computing and fault-tolerant systems. The algorithm was first described by Leslie Lamport in 1990 and serves as a method to achieve consensus among a collection of unreliable processors (nodes) in a network. Consensus algorithms are crucial because they ensure that a cluster of distributed systems can agree on a single data value such as the state of a database or the order of transactions, which is essential for system consistency and reliability.
What is Consensus?
In distributed systems, consensus involves multiple nodes agreeing on a single data value among many. This is challenging especially in an environment where system components may fail or messages may be lost or corrupted. Consensus algorithms must be:
- Fault-tolerant: They should be able to reach an agreement even if some of the nodes fail.
- Consistent: All non-failing nodes must agree on the same value.
- Available: The system should continue to operate, despite some failures.
The Paxos Algorithm Explained
Roles in Paxos
Paxos divides nodes into three roles:
- Proposers
- Acceptors
- Learners
- Proposers advocate for a particular value to be agreed upon.
- Acceptors vote for proposals and agree to values.
- Learners find out what value has been chosen.
Basic Process
The Paxos protocol operates in two main phases to reach a consensus:
- Phase 1: Prepare
- A proposer selects a proposal number and sends a prepare request to a majority of acceptors.
- If an acceptor receives a prepare request with a proposal number greater than any it has previously seen, it promises not to accept any proposals numbered less than and responds to the proposer with the highest-numbered proposal (if any) that it has accepted so far.
- Phase 2: Accept
- If the proposer receives responses from a majority of acceptors to its prepare requests, it sends an accept request to each of those acceptors. This request includes a proposal number and the value proposed or null if no value has yet been accepted.
- Acceptors confirm this accept request unless they have subsequently promised to respond to a prepare request with a higher number.
Consensus Achievement
Consensus is achieved when a majority of acceptors have accepted the same proposal.
Example of Paxos in Action
Imagine a distributed database with data replicas, needing to agree on the version of a particular record. If several nodes propose updates, Paxos helps ensure that the database extracts a single consistent update sequence, despite node failures or network issues.
Benefits and Drawbacks
| Benefit | Explanation |
| Fault-tolerance | Paxos can tolerate up to nodes failing (for total nodes). |
| Consistency Guaranteed | Once consensus is reached, all complying nodes agree on the same value. |
| Minimally Blocking | Progress can be made as long as a majority of nodes operate correctly. |
| Drawback | Explanation |
| Complexity | Paxos is notoriously difficult to understand and implement correctly. |
| Latency | In scenarios with many nodes or high message loss, Paxos can have high latency. |
| Resource Intensive | Requiring multiple phases and messages can strain network and compute resources. |
Practical Use Cases
Paxos has been used in various high-profile distributed systems:
- Google Chubby - a lock service for loosely-coupled distributed systems.
- Microsoft’s Autopilot - for cluster management of large datacenter applications.
Conclusion
Paxos plays a central role in distributed systems where ensuring data consistency and fault tolerance is crucial. Despite its operational and conceptual complexity, when implemented correctly, Paxos provides a reliable method for diverse systems to reach consensus efficiently. Optimizations and variations of Paxos, such as Multi-Paxos, have been developed to handle specific scenarios or improve efficiency, confirming the algorithm’s foundational importance in computer science.
Related reading
- paxos vs raft for leader election
- paxos why do ids have to increase monotonically?
- PBFT consensus algorithm and double spending
- PBFT view-change What happens to committed operations after the valid snapshot?
- Peak-finding algorithm for Python/SciPy
- Peak detection in a 2D array
- PBFT Why cant the replicas perform the request after 2/3 have prepared? why do we need commit phase?
- Peer to peer replication in SQL Server 2005/08

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.