Learn

Navigate through learn topics

CQRS and Event Sourcing

Separate read/write models and store the source of truth as a stream of events

Last updated: 8/15/2025

CQRS and Event Sourcing

CQRS separates command (writes) and query (reads) models for scalability and clarity. Event sourcing stores all changes as an append-only log; the current state is a projection of past events.

When it fits

  • Auditability and a complete history are required (finance, compliance)
  • Read and write workloads scale differently

Risks

  • Operational complexity: projections, replays and schema evolution
  • Event design mistakes are costly to undo

Real-world examples

  • Trading and payments systems maintain ledgers as event streams for full audit trails
  • E-commerce order workflows rebuild customer views from events for speed while keeping authoritative events for consistency

Practical tips

  • Version events and script safe migrations
  • Keep projections disposable and rebuildable