Home

2PC

Two-Phase Commit (2PC) is a distributed algorithm used to ensure atomic commitment of a transaction across multiple nodes, or participants, in a distributed system. It guarantees that either the transaction is committed on all participants or it is aborted on all, preserving atomicity and consistency in the presence of failures. It is commonly used in distributed databases and resource managers that need cross-node transactional guarantees.

In 2PC, there are two phases. Phase one is the prepare (voting) phase. The coordinator sends a

The protocol relies on durable logging and reliable messaging. If the coordinator fails after the prepare messages

Variants and limitations include three-phase commit (3PC), which attempts to reduce blocking at the cost of

prepare
request
to
each
participant,
and
each
participant
writes
a
durable
log
entry
and
votes
Yes
if
it
can
commit
the
transaction
given
its
local
state,
or
No
if
it
cannot.
If
any
participant
votes
No
or
a
timeout
occurs,
the
coordinator
will
abort
the
transaction.
Phase
two
is
the
commit/abort
phase.
If
all
participants
voted
Yes,
the
coordinator
sends
a
commit
command;
otherwise,
it
sends
an
abort
command.
Participants
then
perform
the
corresponding
action
locally
and
acknowledge
completion.
have
been
sent
but
before
the
final
decision,
participants
may
remain
in
a
prepared
state,
causing
the
system
to
block
until
a
new
coordinator
recovers
and
issues
a
decision.
This
blocking
behavior
is
a
key
drawback
of
2PC.
Recovery
typically
requires
a
durable
log
and
a
newer
coordinator
or
recovery
process
to
determine
and
enact
the
final
decision.
extra
complexity,
and
optimizations
such
as
timeouts
and
presumed-commit
or
presumed-abort
strategies.
In
practice,
2PC
is
simple
and
reliable
for
short-lived
transactions
but
can
impact
scalability
and
latency
in
large,
distributed
deployments.