Advanced Distributed Systems #2PC #Saga #Outbox #idempotency

Distributed Transactions

5 exercises — master distributed transaction vocabulary: 2PC vs Saga trade-offs, compensating transactions, the Outbox pattern for reliable event publishing, lost updates, and idempotency key implementation.

0 / 5 completed
Distributed transactions quick reference
  • 2PC — prepare + commit phases; ACID atomicity; blocking on coordinator failure. Use for co-located, short-lived XA resources.
  • Saga — sequence of local transactions + compensating transactions. Use for cross-service, long-lived flows.
  • Compensating transaction — application-level semantic undo for an already-committed Saga step.
  • Outbox pattern — write event to outbox table in same DB transaction; relay publishes to message broker. Solves dual-write.
  • Lost update — concurrent read-modify-write overwrites each other. Fix: optimistic locking (version), SELECT FOR UPDATE, or atomic DB operation.
  • Idempotency key — caller-generated UUID; service stores key → result; retries return cached result without re-executing.
1 / 5

An architect explains: "We use Two-Phase Commit (2PC) to coordinate our order and inventory updates. A colleague says '2PC is blocking — you should use the Saga pattern instead.' When is 2PC actually appropriate?"