The Desi Architect
Notes / Docker Sandboxes / Distributed Transactions: Orchestrated Saga with Compensating Actions
Docker Sandboxes · Tier 3: Reliability & Messaging · Lab 45

Distributed Transactions: Orchestrated Saga with Compensating Actions

Buy one iPhone across an order service, a payment service and an inventory service, each with its own database. Break a different step each time and watch the orchestrator undo what already succeeded, in reverse order, even when the undo itself fails.

Time35 minutes
StackPython 3Ports 15470, 15471, 15472
MemoryAbout 140 MB
Before thisLab 41Transactional Outbox Pattern & Pol
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Explain why a distributed transaction is not available across services, and what a saga does instead.
  • Write a compensation for each step, and run them in reverse order.
  • Explain why compensations must be idempotent and retried.
  • Name what a saga gives up: isolation and a simple "all or nothing".

Before you start

Finish Lab 41 (Transactional Outbox) and Lab 42 (API Idempotency Keys) first. You should know why a retry can arrive twice. Docker Desktop and Python 3 are needed.