Skip to content
Computing Rich #2pc#distributed-tx#consensus

Two-Phase Commit

Coordinator asks every participant to prepare, then to commit. Blocks on coordinator failure.

A free, animated two-phase commit you can read here or embed on any website, from Scrollchart.

Two-Phase Commit

Two-Phase Commit (2PC)All-or-nothing atomicity across distributed nodes. Coordinator failure blocks participants.Phase 1: PreparePhase 2: CommitCoordinatorParticipant 1Participant 2Participant 3lock heldlock heldlock heldall YEScommittedcommittedcommittedFailure ScenarioCoord.ParticipantPREPAREVOTE YESCRASHBLOCKEDholds locksawaits commitor abort signalFix: 3PC or Paxos-basedcoordinator election2PC guarantees atomicity but is blocking. Used in XA transactions (MySQL, PostgreSQL). Coordinator SPOF resolved by Saga pattern or consensus protocols (Raft).

Coordinator and three participants. Phase 1: prepare requests, all reply yes/no. Phase 2: if all yes, commit; else abort. Failure animation: coordinator dies after prepare, participants block holding locks.

Good for

  • Distributed transaction design in microservices
  • Explaining XA protocol failures and alternatives
  • Teaching consensus vs. coordination tradeoffs in CS courses

Source & accuracy

This two-phase commit is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Consensus through prepare and commit phases

Two-phase commit (2PC) coordinates atomic changes across multiple independent systems. The coordinator sends a prepare request to every participant: can you commit this change? Each participant locks resources and reports yes or no. If all say yes, the coordinator sends commit and they apply the changes. If any say no, the coordinator sends abort and all roll back. This guarantees that either all systems commit or none do, even if failures occur between phases.

The blocking and failure problem

2PC has a fundamental weakness: if the coordinator crashes after prepare but before commit, participants remain locked indefinitely, unable to unilaterally decide to commit or abort. They must wait for the coordinator to recover. This blocks resources and transactions, degrading availability. Long-running transactions with 2PC can lock critical data for seconds or minutes, starving other requests. Most distributed systems avoid 2PC when possible.

Modern alternatives

Saga patterns break a distributed transaction into a series of local transactions with compensating actions for rollback. Event sourcing records every state change, enabling replaying to rebuild state. Both avoid global blocking. 2PC remains useful within a single database cluster or for occasional critical operations where availability loss is acceptable, but microservices architectures have largely moved away from it.

Embed this diagram

Add this animated two-phase commit to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated two-phase commit for any website.
Who uses it
Developer blogs, DevOps / SRE sites, CS educators.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="two-phase-commit" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Two-Phase Commit" for my website?
Scrollchart provides "Two-Phase Commit" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a two-phase commit in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.