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.
Distributed Transactions β Part 3: System Design & Interview Mastery
maang.io System Design Series
What is this?
You now know the machinery β 2PC and its blocking problem, why 3PC is a museum piece, sagas, TCC, and the outbox. This chapter is where that knowledge turns into signal. Interviewers almost never ask "explain 2PC" in a vacuum. They drop you into a design β "place an order across these five services" β and watch whether you reach for the right consistency tool, defend the trade-off, and handle the crash without hand-waving. Getting that right is one of the clearest Staff/Principal tells there is, because distributed transactions are pure trade-off reasoning: there's no free atomicity, and they want to see you spend the budget wisely.
Our travel agent has taught you everything she can. Now you sit in her chair.
The one-line idea: interviewers use distributed transactions to test whether you'll avoid coordination when you can, choose the cheapest mechanism that meets the correctness bar when you can't, and name exactly what breaks on failure β not whether you can recite the 2PC message sequence.
Sign in to continue reading
The rest of this lesson is available with a free account. Signing in with Google or Microsoft is free.
Sign in to read the full lesson