Knowledge Guide
HomeSystem DesignScalable Systems (Advanced Topics)

2PC vs Saga vs TCC — Distributed Transactions

One transaction, many services

A single business action — “place an order” — may touch Order, Payment, and Inventory services, each with its own database. There’s no single COMMIT across them. Three patterns reconcile this, trading consistency, locking, and complexity differently.

Two-Phase Commit (2PC) — strong, but blocking

A coordinator runs two phases: Prepare (every participant locks resources and votes “ready”), then Commit (if all voted yes, everyone commits; otherwise everyone aborts). It gives ACID across services — but it’s synchronous and blocking: if the coordinator crashes after Prepare, participants sit holding locks, unable to proceed. That fragility is why 2PC is avoided in high-scale systems.

Two-phase commit: prepare phase then commit phase coordinated by a transaction coordinator
Two-phase commit: prepare phase then commit phase coordinated by a transaction coordinator

Saga — local transactions + compensation

A Saga replaces the distributed lock with a sequence of local transactions, each with a compensating transaction that semantically undoes it. If step 3 fails, you run the compensations for steps 2 and 1 (refund, release stock). Two flavours: choreography (services react to each other’s events) and orchestration (a central coordinator drives the steps). No locks, no blocking — but only eventual consistency and no isolation, so you must design idempotent steps and handle intermediate states.

Saga pattern: a sequence of local transactions with compensating transactions on failure
Saga pattern: a sequence of local transactions with compensating transactions on failure

TCC (Try-Confirm-Cancel) — explicit reservations

TCC splits each step into Try (reserve resources — e.g. hold the stock, authorize but don’t capture payment), then Confirm (commit the reservation) or Cancel (release it). It gives more control than a Saga and avoids 2PC’s locks, at the cost of building three operations per service.

Choosing

2PCSagaTCC
ConsistencyStrong (ACID)EventualEventual, reservation-based
LockingHolds locks across the txnNone (compensations)Soft reservation
Failure modeCoordinator crash blocks participantsCompensations may be complexMore code, explicit cancel paths
Best forFew services, short txns, strict ACIDMicroservices, long-running flowsWhen you need isolation-ish reservations

Takeaways


Re-authored for this guide. Formulas are standard public-domain engineering math (Bloom 1970; Lamport/Ongaro–Ousterhout for consensus; Gray for 2PC). Diagrams adapted from Karan Pratap Singh’s System Design (MIT) and concepts from Designing Data-Intensive Applications.

🤖 Don't fully get this? Learn it with Claude

Stuck on 2PC vs Saga vs TCC — Distributed Transactions? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **2PC vs Saga vs TCC — Distributed Transactions** (System Design) and want to truly understand it. Explain 2PC vs Saga vs TCC — Distributed Transactions from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **2PC vs Saga vs TCC — Distributed Transactions** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **2PC vs Saga vs TCC — Distributed Transactions** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **2PC vs Saga vs TCC — Distributed Transactions** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes