openskills.info
Course Preview

Distributed Transactions and Two-Phase Commit

Distributed transactions make one logical change across multiple independent data stores or services. Two-phase commit coordinates those participants so they all commit or all roll back, even though failures can interrupt the decision process.

itDatabases and data storage

Distributed Transactions and Two-Phase Commit

A distributed transaction is one transaction whose work spans more than one independently managed resource. A resource might be a database, a database shard, or a transactional message system. The transaction must finish with one atomic outcome: every participant commits, or every participant rolls back.

Two-phase commit, abbreviated 2PC, is the classic protocol for reaching that atomic outcome. A transaction manager acts as the coordinator. Each resource manager controls one participant, sometimes called a branch. The coordinator first asks every participant whether it can commit. It then records and announces the final decision.

This protocol solves atomic commitment. It does not solve every distributed-systems problem. It does not choose the correct business operation, provide isolation by itself, or keep an application available through every failure. Its guarantee depends on durable records, correct recovery, and participants that honor the protocol.

Why a local commit is not enough

Consider a transfer between two databases. One database debits an account. The other credits another account. If the first local commit succeeds and the second fails, the overall transfer is incomplete. Calling the second database again might help, but a timeout does not reveal whether its first attempt committed.

A distributed transaction gives both writes one global transaction identifier. The coordinator tracks the global transaction. Each resource manager tracks its local branch. The protocol delays the irreversible outcome until every branch reports that it is prepared.

The important invariant is atomicity, not simultaneous execution. Participants can receive the final decision at different times. They must eventually apply the same recorded decision.

The actors and durable state

Continue the course

This section is part of the paid course.

See pricing to subscribe, or log in if you already have access.

Where this skill leads

Relevant careers

See how this topic contributes to broader role-level skill maps.

Sources