Files
nexus/sreweekly/markdown/305/03-paxos.md
2026-09-12 17:23:01 +08:00

55 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Paxos
- **期号**: SRE Weekly Issue #305(2022-01-16)
- **作者**: Martin Fowler
- **链接**: https://martinfowler.com/articles/patterns-of-distributed-systems/paxos.html
## 简介
This is an approachable explanation of the Paxos algorithm with examples, diagrams, and code.
## 正文
# Paxos
Use two consensus building phases to reach safe consensus even when nodes disconnect
## Problem
When multiple nodes share state, they often need to agree between
themselves on a particular value.
With [Leader and Followers](https://martinfowler.com/leader-follower.html), the leader decides and passes its value to the
followers. But if there is no leader, then the nodes need to determine a
value themselves. (Even with a leader-follower, they may need to do this to
elect a leader.)
A leader can ensure that replicas safely acquire an update by using
[Two-Phase Commit](https://martinfowler.com/two-phase-commit.html), but without a leader we can have competing nodes
attempt to gather a [Majority Quorum](https://martinfowler.com/majority-quorum.html). This process is further
complicated because any node may fail or disconnect. A node may achieve
majority quorum on a value, but disconnect before it is able to communicate this
value to the entire cluster.
## Solution
The Paxos algorithm was developed by Leslie Lamport,
published in his 1998 paper [“The
Part-Time Parliament”](http://lamport.azurewebsites.net/pubs/lamport-paxos.pdf). Paxos works in three phases to make sure
multiple nodes agree on the same value in spite of partial network or
node failures. The first two phases act to build consensus around a
value and the last phase then communicates that consensus to the remaining
replicas.
- Prepare phase: Establish the latest [Generation Clock](https://martinfowler.com/generation-clock.html) and gather any already accepted values.
- Accept phase: Propose a value for this generation for replicas to accept.
- Commit phase: Let all the replicas know that a value has been chosen.
for more details go to [Chapter 11](https://learning.oreilly.com/library/view/patterns-of-distributed/9780138222246/ch11.xhtml) of the online ebook at oreilly.com
![](https://martinfowler.com/books/joshi.jpg)
This pattern is part of [Patterns of Distributed Systems](https://martinfowler.com/)
23 November 2023