SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
  • The Problem with Distributed Transactions
  • Two-Phase Commit (2PC)
  • Three-Phase Commit (3PC)
  • SAGA Pattern
  • Try-Confirm-Cancel (TCC)
  • Compensating Transactions
  • Outbox Pattern
  • Exactly-Once Processing
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Distributed Systems/Distributed Transactions

Three-Phase Commit (3PC)

2PC with an extra step so a crashed coordinator does not leave everyone stuck.

⏱ 12 min readAdvancedHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Three-Phase Commit (3PC) is two-phase commit with one extra step in the middle, called pre-commit. The goal is to fix 2PC's big weakness: participants getting stuck when the coordinator crashes.

  • The phases are: CAN-COMMIT (vote), PRE-COMMIT (everyone is told the outcome will be commit), then DO-COMMIT.
  • The extra step means no participant commits before everyone knows that everyone said yes. So after a coordinator crash, the others can safely decide using timeouts.
  • It is non-blocking, but only if the network never splits. With a network partition it can give different answers to different parts.
  • It costs one more round trip, so it is slower than 2PC. Because of this, it is rarely used in real systems. Paxos or Raft are used instead.

02Concept: What is it?

Remember the problem with 2PC. After voting YES, a participant is in a ready state. If the coordinator dies, it does not know the outcome. Some others might have committed already, so it cannot abort. Someone might have voted NO, so it cannot commit. It must wait.

3PC splits the ready state into two. After the vote, the coordinator sends PRE-COMMIT, which means "everyone voted YES, and I am about to commit." Participants reply ACK. Only then does the coordinator send DO-COMMIT. The key rules are:

  • A participant that has not received PRE-COMMIT is uncertain. It knows nobody has committed yet, because commits only come after all PRE-COMMITs. So after a timeout it can safely abort.
  • A participant that has received PRE-COMMIT knows every vote was YES. After a timeout it can safely commit.
From two phases to three
2PC
❓PREPAREvote
→↓
✅COMMITdecide
3PC
❓CAN-COMMITvote
→↓
🔔PRE-COMMITall said yes
→↓
✅DO-COMMITcommit
The new middle step turns an 'uncertain' wait into a decision rule.
🧠The idea in one line
No one commits until everyone has heard that everyone voted YES. So "I have not heard it yet" always means "it is safe to abort".

03Real-Life Example

🍵The Surprise Party Plan
A group plans a surprise party. The organiser first asks everyone: can you come? (vote). Then the organiser sends a second message: everybody said yes, so get ready to go (pre-commit). Only after everyone confirmed that message does the organiser say: go now (commit). Now suppose the organiser's phone dies. A guest who never got the second message knows nobody has set off yet, so they stay home safely. A guest who did get it knows everyone said yes, so they go. It works, as long as every guest can still reach the others. If the guests are split into two rooms that cannot talk, one room may leave and the other may stay home.
The party plan
Three-phase commit
The organiser
The coordinator
'Can you come?'
CAN-COMMIT (the vote)
'Everyone said yes, get ready'
PRE-COMMIT
'Go now!'
DO-COMMIT
A guest who did not get the 'get ready' message
A participant in the uncertain state: aborts on timeout
A guest who got it
A participant in the pre-committed state: commits on timeout
Two rooms that cannot talk to each other
A network partition, which breaks the safety

04Why Do We Need It?

🔓Fix blocking
Participants can finish the transaction themselves after a coordinator crash, instead of waiting for it.
⏱️Bounded waiting
Timeouts lead to a decision, so locks are not held until the coordinator returns.
🧠A step in the idea's history
It shows why 'one more round' helps, and why it still falls short.
🧪Teaches failure thinking
A good way to practise reasoning about crashes versus partitions.
🎤A common question
Interviewers ask: how is 3PC different from 2PC, and why is it not used much?
🧱A path to consensus
Its flaw motivates Paxos and Raft, which solve agreement properly.
3PC buys non-blocking behaviour with an extra round trip, but only in a world where the network never splits.

05Where Do We Use It?

📚Textbooks and courses
It is a standard topic in distributed systems classes, to compare with 2PC.
🧪Research
It inspired later work on non-blocking atomic commit protocols.
🏢Rare in production
Few real databases use it, because of the partition problem and the extra delay.
🔁Replaced by consensus
Production systems use 2PC with a replicated coordinator (Paxos or Raft) instead.
🎤System design interviews
A way to show that you know the limits of 2PC.
🔬Closed, reliable networks
The only place its assumptions might hold: a small, fast network that never partitions.

06Types / Parts / How It Works

The three phases

PhaseCoordinator sendsParticipants do
1. CAN-COMMITCan you commit?Check if the work is possible. Reply YES or NO. Still no locks are released and nothing is committed.
2. PRE-COMMITEveryone said YES: prepare to commitRecord that the outcome will be commit, and reply ACK. This is the new step.
3. DO-COMMITCommit nowCommit, release locks, reply that they are done.

If any participant votes NO in phase 1, the coordinator sends ABORT to all, as in 2PC.

What a participant does on a timeout

Participant stateWhat it knowsRule on timeout
Uncertain (voted YES, no PRE-COMMIT)No one can have committed yetABORT
Pre-committed (got PRE-COMMIT)Everyone voted YESCOMMIT
Committed or abortedThe matter is closedNothing to do
Where 3PC breaks: a network partition
Room 1 (cut off)
🗄️P1got PRE-COMMIT: commits
Room 2 (cut off)
🗄️P2uncertain: aborts
🗄️P3uncertain: aborts
Commits Aborts
Nobody crashed beyond the coordinator, but the two groups follow different rules.
⚠️Why this is a real flaw
The timeout rules treat "I cannot reach you" as "you crashed". In a partition that is false: the other side is alive and following its own rule. The result is an inconsistent outcome, which is worse than waiting.
Visualizer2PC vs 3PC when the coordinator failsSwitch between the protocols and the failures. Find the case where 2PC blocks, the case where 3PC saves the day, and the partition case where 3PC splits.
Protocol
What fails?

All three participants voted YES. The coordinator crashed before it sent anything else.

What each participant decides on its own, using only the rules of 2PC
🗄️P1Ready: BLOCKED
🗄️P2Ready: BLOCKED
🗄️P3Ready: BLOCKED
Round trips (happy path)
2
prepare, commit
Time when all is well
40 ms
network only
Participants blocked
3
Result
Blocked
2PC is BLOCKED. Each participant is Ready: it voted YES, so it cannot abort alone, and it does not know if the decision was COMMIT, so it cannot commit alone. Locks stay held until the coordinator returns.

A table of the textbook rules, not a network simulation. Real systems that need to avoid blocking use a consensus protocol (Paxos or Raft) to replicate the coordinator, instead of 3PC.

07How to Use It / Steps / Implementation

What to do with this knowledge

  1. 1
    Know the assumptions
    3PC assumes a synchronous network: messages arrive within a known time, and a timeout means a crash. Real networks give no such promise.
  2. 2
    Do not pick 3PC for a real system
    It is slower than 2PC (3 round trips) and unsafe under partitions. It is mostly a teaching tool.
  3. 3
    If you need a non-blocking commit, use consensus
    Replicate the coordinator (or each participant) with Paxos or Raft. That is what Spanner and similar systems do.
  4. 4
    Or avoid the global commit
    Use a SAGA or the Outbox pattern, and accept eventual consistency.
  5. 5
    In an interview, tell the story
    2PC blocks, so 3PC adds pre-commit, which works only without partitions. So real systems use 2PC plus consensus.
  6. 6
    Keep the timeout rules straight
    Uncertain means abort. Pre-committed means commit.
💡A one-sentence comparison
2PC is safe but can block. 3PC is non-blocking but can be unsafe under partitions. Consensus-based commit is safe and live while a majority is reachable.

08Key Terms to Know

TermMeaning in easy words
CAN-COMMITPhase 1: the coordinator asks if each participant can commit
PRE-COMMITPhase 2: the coordinator says everyone voted YES, so the outcome will be commit
DO-COMMITPhase 3: the coordinator tells everyone to commit now
Uncertain stateVoted YES but no PRE-COMMIT yet. Safe to abort on timeout
Pre-committed stateGot PRE-COMMIT. Safe to commit on timeout
Non-blockingParticipants can decide without waiting for a failed coordinator
Network partitionA split where groups of machines are alive but cannot reach each other
Synchronous networkAn assumption that messages arrive within a known time limit
TimeoutA deadline after which a node assumes the other side failed
Recovery protocolA step where the remaining participants elect a new coordinator and decide the outcome
ConsensusAgreement among machines on one value, even with failures (Paxos, Raft)

09Pros, Cons and Trade-offs

✅ Pros
  • Does not block when the coordinator crashes (if the network is reliable)
  • Locks are released after a bounded time
  • Clear rules for what to do on a timeout
  • Helps to understand why 2PC blocks
⚠️ Cons
  • Needs a third round trip, so it is slower than 2PC
  • Unsafe under network partitions: parts can decide differently
  • Assumes timeouts mean crashes, which is not true on real networks
  • More messages and more states to implement
  • Rarely used in production
  • Does not tolerate a participant and coordinator failing together in every case

Trade-offs

ChoiceWe gainWe lose
3PC instead of 2PCNo blocking when only the coordinator crashesA round trip of latency, and safety under partitions
2PC with a replicated coordinatorSafe, and not blocked by one crashMore complexity, but this is how real systems do it
Short timeouts in 3PCFaster recoveryMore false 'crash' detections, so more risk of a split decision
SAGA instead of eitherNo global locks and independenceEventual consistency and compensation code

10Common Problems and Mistakes

Common mistakes

  1. Believing 3PC is just better than 2PC. It is better only when the network never partitions, which cannot be assumed.
  2. Confusing a timeout with a crash. A slow or cut-off node looks the same as a dead one, and acting as if it were dead breaks safety.
  3. Forgetting the extra latency. The extra round trip applies to every transaction, even without failures.
  4. Mixing up the timeout rules. Uncertain aborts. Pre-committed commits. Getting them the wrong way round loses atomicity.
  5. Choosing it for production. Almost nobody does. Use 2PC with replication, or a SAGA.
  6. Ignoring recovery. After electing a new coordinator, the participants still need a careful protocol to find a single outcome.

Things to watch

✂️Partitions
The key danger. Two groups can reach different decisions.
🐌Slow nodes
A node that is slow but not dead may be treated as crashed.
⏰Timeout tuning
Too short gives false alarms. Too long gives long waits.
🔁Extra messages
More round trips means more chances of loss and delay.

11Real-World Examples

📖Academic origin
Dale Skeen described three-phase commit in the early 1980s as a non-blocking improvement over 2PC.
🌍Spanner-style systems
Use 2PC with Paxos-replicated participants, which solves blocking without a third phase.
🪳Distributed SQL databases
Use consensus (Raft or Paxos) per range or shard, and a commit protocol on top.
↩️Microservices
Mostly use SAGA and Outbox, not global commit protocols.
🧑‍🏫Interviews
A classic way to test whether a candidate understands the failure modes of 2PC.
🧱Theory
The impossibility results about consensus (such as FLP) explain why no protocol can be both safe and always live over an asynchronous network.
📝Note
3PC is mainly a stepping stone in the story of distributed agreement. Do not expect to find it in a real database.
The story in three steps
🤝2PCblocks on a crash
→↓add a phase
🔔3PCbreaks on a partition
→↓use consensus
🗳️Paxos / Raftsafe and live with a majority
Each step fixes the last one, and finds a new problem.

12Related Topics to Read Next

Two-Phase Commit (2PC)→

The protocol that 3PC tries to improve.

The Problem with Distributed Transactions→

The reason we need a commit protocol at all.

Network Partitions→

The failure that breaks 3PC.

Consensus Algorithms→

The proper way to get agreement that survives failures.

Paxos→

A safe consensus algorithm used to replicate coordinators.

Raft→

An easier consensus algorithm with the same goal.

SAGA Pattern→

A practical alternative that avoids global commit.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: 2PC with an extra PRE-COMMIT phase, to avoid blocking.
  • ✔Phases: CAN-COMMIT, PRE-COMMIT, DO-COMMIT. Three round trips.
  • ✔Rule: uncertain means abort on timeout. Pre-committed means commit on timeout.
  • ✔Wins: no blocking when only the coordinator crashes.
  • ✔Flaw: a network partition can make two groups decide differently.
  • ✔Cost: one more round trip than 2PC, even when all is well.
  • ✔In practice: rare. Use 2PC with Paxos/Raft, or SAGA.
  • ✔One line: “3PC trades safety under partitions for freedom from blocking, which is usually the wrong trade.”
← Previous
Two-Phase Commit (2PC)
Next →
SAGA Pattern