Question #42 of 60•Microservices•Hard• ~3 min read

What are the trade-offs of Event Sourcing vs CQRS (Command Query Responsibility Segregation)?

Executive Takeaway

Compare immutable event logs, snapshot state replays, and separate read/write data models.

Architectural Breakdown & AnalysisFAANG Aligned

Event Sourcing and CQRS decouple write domain business logic from complex query reporting models.

1. Event Sourcing

  • Instead of storing current state in a DB table row, store an immutable sequence of state-changing events (OrderCreated, PaymentReceived, OrderShipped).
  • Current state is reconstructed by replaying events sequentially.
  • Pros: Complete audit log, time-travel debugging.
  • Cons: Event schema evolution complexity and slow state rebuilds without periodic snapshots.

2. CQRS

  • Separates write operations (Commands) from read operations (Queries).
  • Writes hit a normalized OLTP DB; changes stream via Kafka to populate an optimized read-model DB (e.g., Elasticsearch).
TIP — Production Advice

You can adopt CQRS without full Event Sourcing to scale read/write operations independently.

Key Architectural Comparison

Architecture ParadigmState RepresentationRead ModelAuditabilityRefactoring Complexity
Traditional CRUDMutable rows in database tables.Queries hit same tables or replicas.Lost historical updates without separate audit logs.Low.
Event SourcingImmutable append-only log of domain events.Replayed state from beginning of time or snapshot.100% complete forensic audit trail.High (Event schema migration challenges).
CQRSSeparate Command (Write) and Query (Read) models.Optimized read database (e.g. Elasticsearch).High when combined with event streams.Moderate (Eventual consistency between models).
Previous QuestionHow do you design a Distributed Web Crawler at scale?Next Question How do Leaky Bucket, Token Bucket, and Fixed Window Rate Limiting algorithms compare?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.