Stackbook Logo
data-consistencyestablished · high operational burden

Event Sourcing Patterns

Also known as: event-store, event-sourced, event-sourcing, cqrs-event-sourcing

Intent

Persist state changes as immutable event log, enabling audit trail, temporal queries, replay, and multiple read models.

Problem

CRUD loses history. Audit, debugging, temporal queries hard. New read models require data migration.

Forces

  • Business needs audit trail (who, what, when, why)
  • Need to query state at any point in time
  • Domain events = language of business
  • Rebuilding projections for new read models must be possible

Solution

✓ When to Use

  • Audit/regulatory requirements (financial, healthcare, gov)
  • Complex domain with rich business events
  • Need temporal queries (state at date X)
  • Multiple read models from same write model
  • Debugging: reproduce production state locally

✗ When Not to Use

  • Simple CRUD with no audit needs
  • High-throughput, low-latency writes (event store adds overhead)
  • Team unfamiliar with event-driven thinking
  • Schema evolution complexity not justified

Pros

  • +Complete audit trail by default
  • +Temporal queries: state at any point
  • +New projections without data migration
  • +Event replay for debugging, testing, migration
  • +Domain events align with business language

Cons

  • Event schema evolution is hard (upcasters, migrations)
  • Eventual consistency between write and read models
  • Storage grows unbounded (snapshots, retention policies)
  • Querying current state requires replay (mitigate: snapshots)
  • Learning curve: shifts thinking from state to events

Cost Profile

Infrastructure

Medium — event store (EventStoreDB, Kafka, custom)

Operational

High — monitor lag, schema evolution, replay

Cognitive

High — event modeling, projection design

Failure Modes

  • Event schema breaking change corrupts projections

  • Projection lag → stale reads

  • Snapshot corruption → full replay needed

  • Event ordering violations across partitions

Real-World Examples

Alternatives

  • audit-log
  • cdc
  • outbox-pattern
  • traditional-crud

Related Patterns

  • cqrs
  • outbox-pattern
  • saga-pattern
  • event-carried-state-transfer
  • projection

Competency Domains

data consistencydata statereliability opssecurity complianceeconomics evolution