What is 3 Phase commit?

3 Phase commit is a protocol for distributed transaction management.

Note: 3 Phase commit protocol was created to address issues of 2 phase protocol.

The main motivation for the 3PC algorithm is to address the fact that two-phase commit protocol is blocking in case of a site (site means coordinator or participant) failure.


Like in 2 Phase commit, here also we need a transaction Coordinator Service to take care of the distributed transaction. The transaction coordinator manages the commits to database stores.

What are different phases of 3 Phase commit?

Can-Commit:

  • Here Coordinator just check if slaves are ready to accept transactions, but no data is locked.
  • Coordinator sends a Can-Commit message to all slaves.
  • Slaves reply back with a READY or NOT READY message back:
    • If a slave responds with a NOT READY message or does not respond at all, then the coordinator sends a ABORT message to all the other slaves.

Pre-commit:

  • This is a prepare-to-commit stage.
  • Coordinator sends a prepare-commit message to all nodes, essentially asking the nodes if they are prepared to commit
    • And, if they are not, the commit is aborted.
  • All participants acquire locks on data rows etc, but they don’t actually commit.

Do-Commit:

  • Once the coordinator receives a YES from all nodes stating that they are prepared to commit, the coordinator will send out a commit message.
  • The nodes will then each commit to the specified transaction.

Can you give example, why a Node will send Not Ready message back?

This may happen when a node has a conflicting concurrent transaction or Node has some internal issue going on.


Rakesh Kalra

Hello, I am Rakesh. I have more than 15 years of experience working on IT projects, where I have worked on varied complexity of projects and at different levels of roles. I have tried starting my own startups, 3 of those though none of it were successful but gained so much knowledge about business, customers, and the digital world. I love to travel, spend time with my family, and read self-development books.