Core Concept

Event Sourcing & CQRS

Command Query Responsibility Segregation (CQRS) splits read and write models into isolated layers, while Event Sourcing models states as an immutable log of historical events.


What:

Event Sourcing records all state updates as a sequence of immutable events; CQRS separates the logic for updating data (Commands) from querying data (Queries).

Primary purpose:

Scaling high-concurrency systems, providing perfect audit histories, and optimizing read/write database workloads separately.

Usually used for:

Financial ledgers, collaborative design tools (Figma), e-commerce checkouts, and high-volume analytics systems.

How should I think about this inside system architectures?

🎬 Immutable Event Stream

Never execute database `UPDATE` or `DELETE` statements. State updates are strictly modeled as append-only events (`OrderCreated`, `OrderCancelled`).

🔪 Strict Command/Query Split

Commands (writes) return zero data (only validation state). Queries (reads) bypass the write datastore, pulling directly from optimized read replicas.

📸 Periodic Snapshots

Avoid replaying millions of events on node reboots. Save state snapshots every N events to enable instant system state recoveries.