Distributed Transactions, CQRS, Saga & Consistency
Keeping data correct across services: consistency models, CAP and PACELC, consensus, why two-phase commit rarely fits microservices, the outbox pattern, CDC and idempotency, sagas, CQRS and event sourcing.
Once data lives in more than one service, a single ACID transaction is no longer available. You have to choose a consistency model per use case. You also have to design for partial failure and make every step safe to retry.
Articles
- Consistency & consensusWhat consistency means in distributed systems: the spectrum from linearizability to eventual consistency, session guarantees, CAP and PACELC explained correctly, quorums, Raft consensus, clocks and ordering, isolation levels, and how to choose per use case.
- Distributed transactionsWhy ACID across services is hard: how two-phase commit and XA work, why they rarely fit microservices, distributed SQL as an alternative, and the toolkit that replaces them: local transactions, outbox, idempotency, sagas, TCC and reservations.
- Outbox, CDC & idempotencyThe three patterns that make event-driven systems reliable: the transactional outbox (polling vs log-based CDC with Debezium), the inbox and idempotent consumers, idempotency keys for APIs, deduplication strategies, and ordering.
- Saga patternManaging business transactions across services with sagas: local transactions and compensations, choreography vs orchestration, saga state machines, pivot and retriable steps, isolation countermeasures (semantic locks, commutative updates), durable execution with Temporal, and testing and observability.
- CQRS & event sourcingSeparating writes from reads with CQRS, storing state as events with event sourcing, aggregates and projections, snapshots, upcasting and GDPR, read-model consistency, when to use each pattern, and the tools.
- Case study: order sagaA complete design for e-commerce or banking-product order processing across microservices: service boundaries, the orchestrated saga with Temporal, outbox and CDC, idempotency, CQRS read models for order tracking, failure scenarios, consistency guarantees, observability and trade-offs.