<aside>

This section is part of the 5-hour Microservices course by Mukul Raina

SLIDE 85: Section Intro

Section 6: Distributed Transactions, Sagas, and Consistency

Section 5 established that each service owns its own database. This section confronts the hardest consequence of that rule: when a business operation spans multiple services, how do you keep data consistent across them without a shared transaction?

In a monolith, you wrap everything in a database transaction. If payment fails, the order is rolled back, inventory is released, and the database is consistent. In microservices, there is no shared transaction. Payment lives in one database, inventory in another, orders in a third. When payment fails after inventory has already been reserved, you need a strategy that goes far beyond BEGIN and ROLLBACK.

This section teaches that strategy. It is the highest-signal material in this course for senior-level interviews.

What We Will Cover:

  1. Why local ACID transactions do not work across service boundaries
  2. Two-phase commit (2PC) and why it is usually avoided
  3. The saga pattern: orchestration and choreography
  4. Compensating transactions for undoing completed steps
  5. The transactional outbox and inbox patterns for reliable messaging
  6. Idempotency, at-least-once delivery, and the exactly-once myth
  7. Dead-letter queues, retry strategies, and partial failure handling
  8. State machines for managing service lifecycles
  9. A complete worked example: e-commerce checkout saga with failure cases
  10. Human intervention for unrecoverable failures

Where This Appears in Real Systems:

Every time you place an order on a platform like Amazon, a saga coordinates order creation, inventory reservation, payment authorization, and shipment scheduling across independent services. When payment fails, compensating transactions release inventory. When shipping fails after payment, the system must decide between retrying, refunding, or escalating to a human operator. This is the reality of distributed consistency.