Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/Microservices & Service Mesh
DISTRIBUTED SYSTEMS & ARCHITECTURE · SUBTOPIC

Saga & Transactional Outbox Patterns

Keep multi-service workflows consistent without fragile Two-Phase Commit (2PC).

AdvancedPart of Microservices & Service Mesh
Practice in AI HLD
Subtopics in Microservices & Service Mesh (2)
OverviewSaga & OutboxDiscovery & Mesh

In plain words

If booking a trip involves Flight + Hotel + Car across three companies, you don’t freeze all three companies while paying (2PC). Instead, book step-by-step, and if Car fails, automatically run compensating cancellations on Hotel and Flight (Saga).

Think of it like…

Booking Flight, then Hotel, then Car - and canceling Flight/Hotel if Car sells out.

Loading interactive diagram
Loading interactive exercise

Theory & how it works

Why the Transactional Outbox solves "Dual Writes"

If your code saves an order to Postgres and THEN tries to publish an OrderCreated message to Kafka, a crash right between those two lines leaves the order saved with no event ever published! The Outbox Pattern writes the order AND an outbox_events row inside the same SQL transaction, and a worker/CDC relays outbox rows reliably to Kafka.

Key points & practical guide

Summary checklist

  • Avoid 2PC across independent microservices
  • Saga = sequence of local transactions + compensating actions on failure
  • Outbox pattern makes DB commit + Kafka publish atomic

When to use it

  • E-commerce checkout, travel booking, multi-service workflows

Watch out for

  • Forgetting idempotency on compensating actions (what if refund runs twice?)

Quick check

Loading quiz
Parent topic
Microservices & Service Mesh
Next subtopic
Service Discovery & Service Mesh (Envoy/Istio)