Distributed Transactions & Idempotency
Difficulty: Hard | Topic #30
What to Learn
Two-phase commit (2PC) and its limitations, Saga pattern (choreography vs orchestration), idempotency keys for safe retries, compensating transactions for rollback, outbox pattern for reliable event publishing.
Resources
- Hello Interview: Multi-step Processes ↗
- ByteByteGo: Distributed Transactions — 2 Phase Commit vs Saga Pattern ↗
- Arpit Bhayani: Two-Phase Commit in Distributed Transactions ↗
Covered by Problems
| Problem | Difficulty | Link |
|---|---|---|
| Online Auction | Medium | → |
| Payment System | Hard | → |
| Stock Trading Platform (Robinhood) | Hard | → |
Key Concepts to Master
- 2PC coordinator failure and the blocking problem
- Saga pattern — break a distributed transaction into local transactions with compensating actions
- Choreography (event-driven) vs orchestration (central coordinator) Sagas
- Idempotency key stored with the transaction to make retries safe
- Transactional outbox pattern to atomically write to DB and publish an event