Design Patterns
Circuit Breaker, Saga, CQRS, Cache-Aside and other distributed patterns
11 lessons
Event Sourcing / CQRS
CQRS pattern: Command side, Event Store, Kafka event bus, Read-side projections, cache, event replay
[PATTERN] Saga Orchestration
Central orchestrator coordinates distributed transaction: Order, Payment, Inventory, Shipping with compensating rollbacks
[PATTERN] Saga Choreography
Event-driven saga without orchestrator: services communicate via Kafka event bus with compensating events
[PATTERN] Two-Phase Commit (2PC)
Classic distributed transaction: Coordinator + 3 Participants, PREPARE/VOTE/COMMIT/ROLLBACK phases
[PATTERN] Transactional Outbox
Solve dual-write problem: DB + outbox in one transaction, relay publishes to Kafka, at-least-once delivery
[PATTERN] Circuit Breaker
Prevent cascading failures: CLOSED -> OPEN -> HALF-OPEN state transitions with fallback responses
[PATTERN] Retry + Exponential Backoff
Handle transient failures: retry with 1s -> 2s -> 4s backoff, jitter, dead letter queue on max retries
[PATTERN] Bulkhead
Isolate resources: separate thread pools per service prevent one slow service from taking down others
[PATTERN] API Gateway
Single entry point: rate limiting, JWT auth, routing, API composition (BFF pattern)
[PATTERN] Cache-Aside (Lazy Loading)
Caching strategy: cache hit/miss, write invalidation, thundering herd (cache stampede) problem
[PATTERN] Strangler Fig Migration
Incremental monolith decomposition: proxy routing, CDC data sync, shadow traffic, phased migration