1. Home
  2. Explore
  3. Computer Science
  4. Paxos Consensus Algorithm

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Paxos Consensus Algorithm

Speaker 1Speaker 2

Paxos Consensus Algorithm

10:23
0:00-10:23
  1. Corey

    Welcome to our introduction to Paxos. It’s a family of distributed algorithms for reaching consensus: getting multiple computers to agree on one result, even when messages can be delayed or lost. We’ll focus on vanilla Paxos, then connect it to a replicated storage system.

  2. Hope

    Let’s clarify what “consensus” means here. Imagine friends trying to choose an afternoon activity. Some suggest a movie, others suggest dinner, and eventually some people change their minds until the group settles on one choice. The goal is agreement on a single result—not necessarily for everyone to get their original preference.

  3. Corey

    In Paxos, the key threshold is a majority of acceptors agreeing on a proposal. Once a majority has accepted the same value, consensus has been reached. The agreement may take time to become known to everyone, but learners can discover it by receiving messages or by asking about the result.

  4. Hope

    And the system has to tolerate imperfect communication. Messages can get lost, or nodes may not hear about a proposal right away. Paxos is designed so that, despite that, the nodes can work toward one consistent result.

  5. Corey

    Why do distributed systems need this? A single computer can serve a growing number of users for a while, and you can upgrade its CPU or memory. But one machine has limits, so eventually you may need multiple computers working together.

  6. Hope

    One arrangement is a leader and replicas. Clients send proposed writes to the leader, which orders them and sends them to the replicas. If the leader becomes unavailable, the remaining nodes need consensus to elect a new leader; otherwise, the system can stall.

  7. Corey

    Another arrangement is peer-to-peer: all nodes play equal roles. They exchange proposals and must agree on which operation comes next, so operations are eventually applied in the same order everywhere. That requires ongoing consensus. Either way, consensus helps keep the system coordinated.

  8. Hope

    Vanilla Paxos describes three roles. Proposers suggest values, acceptors participate in deciding whether a value is accepted, and learners find out what value was agreed on. In an actual system, one server can take several roles—or even all three.

  9. Corey

    Acceptors need to know how many nodes make up a majority. The important mathematical fact is that any two majorities overlap in at least one acceptor. That overlap is what helps Paxos prevent incompatible proposals from both winning.

  10. Hope

    Paxos nodes also need persistence: an acceptor must not forget what it has accepted. The speaker notes that some Paxos variants address different persistence assumptions, but vanilla Paxos relies on nodes retaining that information.

  11. Corey

    One more essential point: a single Paxos run decides one value. That value does not later change as part of the same run. If an application needs its data to evolve, it uses another run for another decision.

  12. Hope

    Let’s walk through a run with one proposer and three acceptors. A majority is two. The proposer begins by sending a PREPARE message with an ID to a majority or to all the acceptors.

  13. Corey

    The ID must be unique and never reused. For example, different proposers could use distinct number sequences. If a proposer times out, it retries with a new, higher ID. The ID helps order proposals; it is an internal Paxos detail, not the application value being decided.

  14. Hope

    When an acceptor receives PREPARE with an ID, it checks whether it has already promised to ignore requests with that ID. If it has, it ignores the message. Otherwise, it promises to ignore lower IDs and replies with a PROMISE for the new ID.

  15. Corey

    Suppose the proposer sends PREPARE 5. When it receives promises from a majority, no lower ID can also get promises from a majority. Any two majorities overlap, and the acceptor in the overlap has promised not to honor a lower ID.

  16. Hope

    After getting a majority of promises for ID 5, the proposer sends ACCEPT REQUEST 5 with a value to a majority or all acceptors. If this is the proposer’s first attempt and it has heard of no previously accepted value, it can use the value it originally wanted to propose.

  17. Corey

    An acceptor receiving an ACCEPT REQUEST checks its promise. If it has promised to ignore requests with that ID, it ignores the request. Otherwise, it accepts the ID and value, and sends an ACCEPT message to the proposer and to the learners.

  18. Hope

    If a majority of acceptors accept the same ID and value, consensus is reached on the value. The ID itself is not the consensus result. So if two of the three acceptors accept ID 5 with ‘cat,’ the agreed value is ‘cat.’

  19. Corey

    A proposer or learner can know that consensus has been reached when it receives ACCEPT messages from a majority for the proposal. That’s how learners can find out the chosen value, even though they don’t initiate the decision.

  20. Hope

    So there are three sequential milestones: first, a majority promises an ID; second, a majority accepts an ID and value, which means consensus has been reached; and third, a proposer or learner receives a majority of ACCEPT messages and knows that it happened.

  21. Corey

    Now let’s consider a second proposer that doesn’t know about the first one’s progress. It sends PREPARE 4 after a majority has already promised ID 5. It might receive a promise from one acceptor, depending on timing, but it cannot get a majority, because the majority that promised 5 will reject the lower ID where their sets overlap.

  22. Hope

    The second proposer times out and tries again with a higher ID, say 6. The acceptors can promise 6, but there’s an important rule: if an acceptor has already accepted a value, it includes that previously accepted ID and value in its promise.

  23. Corey

    When the proposer receives a majority of promises, it checks whether any of them report an accepted value. If none do, it may choose its own value. But if one or more promises include accepted values, it must use the value associated with the highest accepted ID it learned about.

  24. Hope

    So if the promises report that ‘cat’ was accepted with ID 5, the proposer must send ACCEPT REQUEST 6 with ‘cat,’ not with a different value. The acceptors can accept that higher-ID request, and learners can discover the same consensus from the resulting ACCEPT messages.

  25. Corey

    That rule is what preserves the decision across later proposals. A higher ID may be used to carry the value forward, but it cannot replace an already accepted value with a different one once the protocol’s promises and majorities constrain the proposals.

  26. Hope

    Let’s look more closely at how majorities handle competing proposals. Suppose proposer one sends PREPARE 5 and proposer two sends PREPARE 4. Messages can arrive in different orders at different acceptors because of different locations and latencies. Once proposer one has promises from a majority, proposal 4 can no longer get a majority.

  27. Corey

    But contention can also happen between higher IDs. One proposer might get a majority of promises for 5, then another might get a majority for 6. Proposal 5 may then fail to proceed, and the first proposer may retry with an even higher ID, potentially disrupting the second.

  28. Hope

    If proposers repeatedly step over one another like that, the run can stall. A possible remedy is exponential backoff: after retries, proposers wait longer before trying again. That can give one proposal time to complete, so a majority can accept a value and end the run.

  29. Corey

    There’s another way to understand the majority rules after a value is accepted. Suppose a majority accepts ID 5 with ‘cat.’ A lower-ID proposal can’t be accepted by a majority, because it would need promises from a majority that conflicts with the promises for the higher ID.

  30. Hope

    And a higher-ID proposal can still make progress, but it has to preserve ‘cat.’ A majority of promises for the higher ID must overlap with the acceptors that accepted the earlier value, so at least one promise reports that accepted value. The proposer then has to carry it forward.

  31. Corey

    That also explains how a proposer or learner can recover information it missed. A later proposer may start a higher-ID attempt, learn the accepted value through the acceptors’ promises, and propose that value again. The protocol can thus help the node discover the decision.

  32. Hope

    Now let’s apply Paxos to storage. A single Paxos run decides only one value, so it’s not enough by itself for something changeable, like a bank balance. A common approach is a replicated log: each log position gets its own consensus decision.

  33. Corey

    Position zero can represent the account’s initial state. A deposit of fifty dollars can be recorded at position one, perhaps along with the resulting balance for efficiency. A withdrawal of twenty dollars can be recorded at position two, with the updated balance. Each change is a new decision at the next log position.

  34. Hope

    Picture three replicas, A, B, and C, storing the same account. Their storage servers can each act as proposer, acceptor, and learner. A client asks a server to read or to write; for a write, that server acts as a proposer and sends the proposal to the acceptors.

  35. Corey

    For example, if the client requests a thirty-dollar withdrawal, the proposer sends it to the three acceptors. If a majority accepts the proposal, consensus is reached, and the agreed value can be written and propagated among the replicas.

  36. Hope

    It’s possible that only two replicas have written the value at first. The third can catch up through a recovery mechanism, or learn about the earlier decision when it later tries to propose another value and receives the accepted value through the promises.

  37. Corey

    So the big picture is: Paxos uses unique proposal IDs, promises, acceptances, and intersecting majorities to let distributed nodes agree on one value despite faulty communication. A replicated log builds on repeated consensus runs to represent a sequence of changing state.

  38. Hope

    And that distinction is worth remembering: one run chooses one value, while a log lets an application make many decisions over time, one position at a time. That’s the core idea behind using Paxos for a distributed storage system.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent