Limited Offer

30% OFF Lifetime Access ($139) with code SYSTEM30

TOPIC #157Advanced 11 min read

Event-Driven Microservices: Choreography vs Orchestration

πŸ’‘
Core Architecture Summary

Design scalable distributed reactive systems: Event choreography, Saga orchestration (Temporal/Camunda), transactional outbox pattern, and change stream integration.

Key Glossary Concepts in this TopicAll Glossary Terms

01.1. The Fatal Dual-Write Hazard in Event-Driven Systems

When building event-driven microservices, developers frequently write code that updates a database and publishes an event in sequence:

typescript
// ❌ THE DUAL-WRITE DISASTER ANTI-PATTERN
async function placeOrder(orderData: OrderDto) {
  // Step 1: Save order to database
  await db.orders.insert(orderData);

  // Step 2: Publish event to Kafka
  await kafkaProducer.send('order-created', orderData);
}

Why Dual-Writes Cause Catastrophic Inconsistencies:

  1. Crash After DB Commit: If the server container crashes (or loses network connectivity to Kafka) immediately after line 4, the order is saved in the database, but the event is never published. The billing and inventory services never receive the event, resulting in an unfulfilled zombie order.
  2. Reverse Order Failure: If you publish to Kafka first and then save to the database, Kafka succeeds, but a database constraint violation fails line 4. Downstream services charge the user's credit card for an order that does not exist in the database!
  3. No Distributed 2PC Support: Traditional ACID transactions cannot span both a relational database and an Apache Kafka cluster.

The Transactional Outbox Pattern with Change Data Capture (CDC) πŸ“¦

PRO Architecture Blueprint

The Transactional Outbox Pattern with Change Data Capture (CDC) πŸ“¦

Guaranteed atomic state mutation and event publishing without dual-write bugs, utilizing PostgreSQL WAL replication and Debezium to stream events to Apache Kafka.

The Transactional Outbox Pattern with Change Data Capture (CDC) πŸ“¦
100%
Rendering visual architecture flowchart...
PRO & LIFETIME CURRICULUM

Unlock Topic #157: Event-Driven Microservices: Choreography vs Orchestration

You are viewing a preview. The full in-depth engineering deep dive, interactive simulators, architecture flowcharts, and self-assessment quizzes for this topic are available with Pro or Lifetime Access.

Production Deep Dive

Failure modes, high-throughput bottlenecks, and real FAANG implementation decisions.

Interactive Blueprints

Interactive system topology diagrams, live parameter simulators, and downloadable SVG charts.

Knowledge Assessment

Staff-level multiple-choice quiz questions with instant feedback and answer explanations.

Cross-Device Progress Sync

Firebase Google authentication automatically syncs your completed topics and quiz scores.

Rate This Architecture Chapter4.9 / 5.0 (38 ratings)

How clear and staff-actionable was this system breakdown?