Distributed Transactions
maang.io System Design Series
A distributed transaction must be all-or-nothing across multiple databases or services. The classic answer, two-phase commit (2PC), coordinates a prepare-then-commit handshake — but a crashed coordinator can leave participants blocked, holding locks. That failure mode is why scalable systems often prefer the Saga pattern (chained local transactions with compensations) and TCC instead.
This deep dive comes in three parts:
- Foundations & Core Concepts — atomic commit, 2PC, and the coordinator-blocking problem.
- Internals — 3PC, Saga (orchestration vs choreography), TCC, and the transactional outbox, with worked numbers.
- Interview — Staff/Principal Q&A: 2PC vs Saga, idempotency, and failure handling.