Skip to content
Home » Commit Protocols

Commit Protocols

Below is a complete, exam-oriented explanation of Commit Protocols—covering Two-Phase Commit (2PC), Three-Phase Commit (3PC), algorithms, messages, failure handling, advantages, disadvantages, and diagrams (text form).


COMMIT PROTOCOLS (Detailed Discussion)

In Distributed Transactions, data is stored on multiple sites.
To maintain Atomicity, all sites involved must either:

Commit the transaction, or
Abort the transaction

Commit Protocols are coordination algorithms used to ensure that all participating sites reach the same decision (commit or abort) even in the presence of failures.

Commit Protocols are essential for:

  • Distributed database systems
  • Multi-site transactions
  • Ensuring data consistency

The two primary commit protocols are:

  1. Two-Phase Commit Protocol (2PC)
  2. Three-Phase Commit Protocol (3PC)

1. TWO-PHASE COMMIT PROTOCOL (2PC)

(Most widely used; very important for exams)

2PC guarantees atomic commit across multiple sites using two phases:

Entities Involved:

  1. Coordinator
    • Controls the overall commit/abort decision
  2. Participants (Cohorts)
    • Each site executing part of the transaction

PHASE 1: PREPARE PHASE (VOTE PHASE)

Coordinator → asks all participants:

“Can you commit?”

✔ Steps:

  1. Coordinator sends PREPARE message.
  2. Each participant does:
    • Check if transaction can commit (constraints, resources, logs).
    • Write log record.
    • Respond with VOTE COMMIT or VOTE ABORT.

✔ Possible Responses:

  • YES (VOTE COMMIT) → ready to commit
  • NO (VOTE ABORT) → cannot commit

If any participant votes NO → coordinator must abort.


PHASE 2: COMMIT PHASE

Coordinator evaluates votes:

✔ Case 1: All sites vote YES

→ Coordinator writes log
→ Sends GLOBAL COMMIT to all participants
→ Participants commit locally
→ Write in logs

✔ Case 2: Any site votes NO

→ Coordinator writes log
→ Sends GLOBAL ABORT
→ All participants abort the transaction


⭐ Text Diagram of 2PC

PHASE 1 (Prepare)
Coordinator → PREPARE → Participants
Participants → YES/NO → Coordinator

PHASE 2 (Commit)
If all YES → GLOBAL COMMIT → Participants
If any NO → GLOBAL ABORT → Participants

Failure Handling in 2PC

✔ Participant Failure

Coordinator sends decision again when participant recovers.

✔ Coordinator Failure

BIG problem: participants are left blocked in “prepared” state.

Participants may wait indefinitely → 2PC is blocking protocol.


Advantages of 2PC

✔ Guaranteed atomicity
✔ Works with all major databases
✔ Simple to implement


Disadvantages of 2PC

Blocking problem (participants wait forever if coordinator crashes)
✘ High communication cost (many messages)
✘ Slow due to disk log writes
✘ Not suitable for highly unreliable networks

Because of these limitations, 3PC was developed.


2. THREE-PHASE COMMIT PROTOCOL (3PC)

(An extension of 2PC; non-blocking)

3PC introduces an extra phase to avoid blocking.

⭐ Phases:

  1. CanCommit? Phase
  2. PreCommit Phase
  3. Commit Phase

PHASE 1: CanCommit?

Coordinator asks participants:

“Can you commit?”

Participants vote YES/NO (same as 2PC).


PHASE 2: PreCommit

(Coordinator sends a “prepare-to-commit” message)

If all vote YES:

Coordinator sends PRE-COMMIT and waits for ACK.

Participants:

  • Perform pre-commit actions
  • Write temporary logs
  • Send ACK

This ensures participants know a commit is coming.


PHASE 3: Commit

After receiving ACKs:

Coordinator sends GLOBAL COMMIT to all participants.

If any failure occurs before PreCommit phase, the system can still safely abort — no blocking.


Why 3PC is Non-Blocking?

3PC ensures:

  • No site stays forever waiting
  • Timeouts allow independent decisions
  • System can reach commit/abort even if coordinator fails

Thus, 3PC is non-blocking, unlike 2PC.


⭐ Text Diagram of 3PC

Phase 1: CanCommit?
Coordinator → CAN COMMIT? → Participants
Participants → YES/NO → Coordinator

Phase 2: PreCommit
Coordinator → PRE-COMMIT → Participants
Participants → ACK → Coordinator

Phase 3: Commit
Coordinator → GLOBAL COMMIT → Participants

Advantages of 3PC

✔ Non-blocking
✔ More robust in network failures
✔ Solves coordinator failure issues


Disadvantages of 3PC

✘ More message overhead
✘ More complicated design
✘ Requires reliable network with bounded delays
✘ Not used widely in commercial DBMS


2PC vs 3PC (Exam Table)

Feature2PC3PC
Phases23
Blocking?YesNo
Communication CostLowerHigher
Failure ToleranceLimitedBetter
ImplementationWidely usedRare in practice
Coordinator FailureCauses blockingNon-blocking

Other Commit Protocols (Short Notes)

1. One-Phase Commit (1PC)

Used when only one participant is involved → no need for voting.

2. Paxos Commit / Raft Commit

Used in distributed cloud systems such as Google Spanner, etc.

3. Saga Pattern

Used in microservices → breaks distributed transactions into smaller steps with compensation.


Perfect 5–6 Mark Short Answer

Commit protocols ensure atomicity in distributed transactions.
The Two-Phase Commit (2PC) protocol uses a prepare phase where participants vote commit/abort, followed by a commit phase where the coordinator issues a global decision.
It ensures atomicity but suffers from blocking if the coordinator fails.
Three-Phase Commit (3PC) adds a pre-commit phase to avoid blocking and allows participants to reach decisions independently during failures.
While 3PC is non-blocking, it has higher communication overhead.