Course contentsShow
← System Design
Lesson 612 of 1,91917. Consensus AlgorithmsFree lesson

The Two-Phase Protocol

How Paxos splits consensus into Prepare and Accept phases to coordinate distributed agreement safely.

The Two-Phase Protocol

What you'll learn: How Paxos splits consensus into Prepare and Accept phases to coordinate distributed agreement safely.

Why Two Phases?

Paxos can't simply have nodes vote once and call it done—network delays, crashes, and competing proposals would create chaos. Instead, Paxos uses a two-phase protocol that separates "reserving the right to propose" from "actually committing a value." This separation prevents conflicting decisions even when multiple proposers compete simultaneously.

Phase 1: Prepare (Discovery & Promise)

In the Prepare phase, a proposer sends a proposal number to acceptors and asks: "Can I propose with this number?"

Acceptors respond with a promise: "I won't accept any proposal lower than yours." If the acceptor already accepted something, it also reveals that value. This phase essentially reserves the right to make a proposal and discovers any values already in progress.

Analogy: Imagine you're bidding on a house. Phase 1 is when you call the seller and say, "I'm interested at this price point." The seller says, "Okay, I'll consider your offer and won't accept anything lower—but someone else already bid $300K."

Phase 2: Accept (Proposal & Commitment)

In the Accept phase, the proposer sends its value (or adopts a value learned in Phase 1) to acceptors. Acceptors check: "Is this proposal number still the highest I've seen?" If yes, they accept it. Once a majority accepts, consensus is reached.

Analogy: You submit your formal offer. The seller checks they haven't promised to consider a higher bid, then signs the contract.

Why This Works

The two phases prevent split decisions. Phase 1 ensures only one proposer can succeed with a given proposal number range, and Phase 2 ensures that value gets committed by a quorum.

Key Takeaway: Paxos's two-phase protocol (Prepare and Accept) safely coordinates distributed consensus by first reserving proposal rights, then committing values once conflicts are resolved.