We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
6 system design questions lean on this idea. Each walks through the full answer.
System Design Masterclass · Distributed Systems Core
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Distributed Systems Core
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
You want to transfer $500 from your checking account to your savings account. On a single database, this is trivial, one transaction, two updates, guarantees handle the rest. Either both updates happen, or neither does. Your money never disappears into the void.
Now imagine your checking account is on a database in Virginia and your savings account is on a database in Oregon. Same two updates, but across two independent database systems that know nothing about each other. How do you ensure atomicity, that both updates happen or neither does? If the Virginia update succeeds but the Oregon update fails, $500 vanishes from your checking account and never appears in savings. Congratulations, you've lost money.
This is the distributed transaction problem, and it has haunted database engineers since the 1970s. The fundamental challenge is that two independent systems can't atomically commit. System A commits its part and tells system B to commit, but the network fails before B receives the message. A has committed, B hasn't. The transaction is partially applied. Money is gone.
Every solution to this problem involves some form of coordination protocol, two-phase commit, three-phase commit, , each with different trade-offs between safety, liveness, and performance. Understanding distributed transactions is understanding why microservices architecture is fundamentally harder than monolithic architecture, and why companies like Google spent a decade building Spanner.
A local transaction on a single database node relies on a simple mechanism: a transaction log (WAL). The database writes all changes to the log. If the transaction completes, it's committed. If the process crashes mid-transaction, the log is replayed on recovery, incomplete transactions are rolled back.
This doesn't work across nodes because there's no shared log. Each node has its own log, its own crash recovery, and its own idea of whether the transaction succeeded.
| Property | Local Transaction | Distributed Transaction |
|---|---|---|
| Atomicity | WAL ensures all-or-nothing | Requires coordination protocol |
| Coordinator | The database engine itself | A separate transaction coordinator |
| Failure mode | Process crash. WAL recovery | Network partition, partial commit |
| Rollback | Replay log, undo changes | Must tell all participants to rollback |
| Single disk write | Multiple network round-trips | |
| Blocking risk | None (single node) | Coordinator crash blocks all participants |
The core dilemma: To ensure atomicity across nodes, you need a coordinator that tells all nodes to commit simultaneously. But "simultaneously" doesn't exist in a distributed system, messages take time, arrive out of order, and sometimes don't arrive at all. The coordinator itself can fail. And during that failure window, participants are stuck, they've prepared to commit but haven't received the final "go" signal.
The approaches:
It is easy and good
“It is really nice and good Please join the course”