---
title: "Short note: Two-phase commit"
subject: "Distributed System"
chapter: 8
key: "semester_7/distributed_system:two-phase-commit-note"
source: https://www.bctengineer.com/q/semester_7/distributed_system/two-phase-commit-note
site: BCT Engineering
---

# Short note: Two-phase commit

Distributed System · Chapter 8: Transaction and Concurrency Control

- Asked in: 2076 Chaitra, 3 marks; 2071 Shrawan, 4 marks (asked 2 times)
- Video: [Two-Phase Commit (2PC) Protocol Explained for Beginners | Distributed Transactions](https://www.youtube.com/watch?v=Ppe3DmNAWrk) — CodeLucky
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/distributed_system/two-phase-commit-note
- Whole chapter: https://www.bctengineer.com/md/semester_7/distributed_system/chapter-8

## Question

Write a short note on two phase commit protocol.

## Short answer

Two-phase commit (2PC) ensures all participants of a distributed transaction either commit or abort. The coordinator sends canCommit? requests; participants reply Yes if prepared, No otherwise. If all votes are Yes, the coordinator sends doCommit, else doAbort. Participants then execute the decision and acknowledge, ensuring atomicity despite failures, though coordinator failure may block.

## Answer

The **two-phase commit protocol (2PC)** makes sure that all servers (participants) of a distributed transaction either all commit or all abort. One server acts as the **coordinator** (usually the one that the client contacted); others are **participants**.

**Phase 1: voting**
1. The coordinator sends **canCommit?** to every participant.
2. Each participant replies **Yes** (it has saved the transaction's changes to permanent storage and is prepared; it can no longer unilaterally abort) or **No** (it aborts at once).

**Phase 2: completion**
3. If all votes (including the coordinator's own) are Yes, the coordinator records the decision and sends **doCommit**; if any vote is No or a timeout occurs, it sends **doAbort**.
4. Participants carry out the decision and send **haveCommitted** to the coordinator.

```text
Coordinator            Participants
   |--- canCommit? ------->|
   |<------ Yes / No ------|
   | (decide, log)         |
   |--- doCommit/doAbort ->|
   |<---- haveCommitted ---|
```

**Failures**
- If a participant crashes before voting, the coordinator times out and aborts.
- A participant that has voted Yes is in the **uncertain** state; if the coordinator fails it must wait (it blocks) or ask other participants for the decision.
- On recovery, servers use their logs to complete the protocol.

**Drawbacks**: blocking if the coordinator fails, and extra messages and delays (about 3N messages for N participants).

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the two-phase commit protocol ensure?
   A. All servers of a distributed transaction either all commit or all abort
   B. Only the coordinator commits
   C. Transactions run faster
   D. Deadlocks never occur
   Answer: A. 2PC provides atomic commitment across all participating servers. (Key point: Goal of 2PC)

2. What does a participant guarantee when it votes Yes?
   A. It has not yet done any work
   B. It has saved the transaction's changes to permanent storage and can no longer unilaterally abort
   C. It will abort later if it wishes
   D. It has already committed and released data
   Answer: B. A Yes vote means the participant is prepared and bound to follow the coordinator's decision. (Key point: Meaning of a Yes vote)

3. What is a main drawback of 2PC?
   A. It cannot abort a transaction
   B. Participants may block if the coordinator fails
   C. It uses no messages
   D. It requires only one server
   Answer: B. Participants in the uncertain state block when the coordinator fails, and the protocol adds messages and delay. (Key point: Failure and drawbacks)

## Related in Distributed System

- [Distributed deadlock; two-phase commit](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-deadlock-2pc) — Distributed System, chapter 8
- [Cascading aborts; atomic commit protocol](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Acascading-aborts-acp) — Distributed System, chapter 8
- [Cascading aborts; three-phase commit](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Acascading-aborts-3pc) — Distributed System, chapter 8
- [Short note: Three-phase commit](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Athree-phase-commit-note) — Distributed System, chapter 8

## Related in other subjects

- [Two-phase simplex method max:Z=3x₁−x₂](https://www.bctengineer.com/question.md?key=semester_3%2Fmathematics_iii%3Atwo-phase-simplex-method-max-z) — Mathematics III, chapter 5, asked 15×
- [Two isotropic sources, equal amplitude, opposite phase](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Atwo-sources-opposite-phase) — Propagation and Antenna, chapter 2, asked 3×
- [Two isotropic sources, same and opposite phase](https://www.bctengineer.com/question.md?key=semester_6%2Fpropagation_and_antenna%3Atwo-sources-same-and-opposite-phase) — Propagation and Antenna, chapter 2, asked 3×
- [1-phase IM not self-starting; two methods](https://www.bctengineer.com/question.md?key=semester_4%2Felectrical_machine%3Asingle-phase-im-not-self-starting-methods) — Electrical Machine, chapter 7, asked 2×
