Sobes.tech
Senior

What is Two-Phase Commit?

sobes.tech AI

Answer from AI

Two-Phase Commit (2PC) is a distributed commit protocol that guarantees the atomicity of transactions in distributed systems. It consists of two phases:

  1. Prepare phase: The coordinator sends a request to all transaction participants to determine if they are ready to commit. Participants respond with 'ready' or 'not ready'.

  2. Commit phase: If all participants are ready, the coordinator sends a commit command, and all participants commit the changes. If at least one participant is not ready, the coordinator sends a rollback command.

Thus, 2PC ensures data consistency but can block resources if the coordinator or participants do not respond.

What is Two-Phase Commit? — Golang - sobes.tech