Overview

Event sourcing persists every change to an entity as an immutable, ordered event log, deriving current state by replaying that history. State-based persistence instead stores and overwrites a single current record, discarding prior values on each update. The choice affects auditability, storage growth, and how much replay/projection machinery you need to build.

Comparison Diagram

Event SourcingAccountOpenedDeposited $100Withdrew $30Deposited $50replayBalance: $120Full history preservedState-Based PersistenceBalance: $0Balance: $100Balance: $70overwriteBalance: $120Only latest state kept

Comparison Table

AspectEvent SourcingState-Based Persistence
Write operationAppends a new immutable event to the log; nothing is ever modified in placeUpdates or overwrites the existing row/record with new values
Data representationSequence of domain events describing what happenedSingle current snapshot of the entity’s fields
Reading current stateReplay events from the start (or from a snapshot) to derive current stateDirect read of the stored row, no reconstruction needed
Concurrency conflictsDetected by checking the expected event stream version before appendingDetected via optimistic locking (row version/timestamp) or DB-level locks
Historical/audit trailNative and complete — every past state is reconstructableNot retained by default; requires a separate audit log or triggers
Schema evolutionOld event versions must be upcast or handled explicitly by consumersExisting rows are migrated or altered directly to the new shape
Storage growthGrows unbounded with every change; needs snapshotting/compaction to stay fastStays roughly proportional to the number of entities, not their history
Query complexityAd-hoc queries need dedicated projections/read models built from the eventsSupports direct ad-hoc SQL queries against the current data

Key Differences

  • Event sourcing stores an append-only event log; state-based persistence stores only the current row
  • Rebuilding state requires replay in event sourcing, versus a simple read in state-based systems
  • Event sourcing gives a native audit trail; state-based needs bolt-on logging to recover history
  • Concurrency is resolved via event versioning instead of row-level locking
  • Storage grows unbounded without snapshots in event sourcing, while state-based storage stays compact

When to Use Each

Event Sourcing

  • Financial Ledgers: Regulatory and compliance needs demand an immutable, replayable record of every transaction, not just the latest balance.
  • Debugging Production Issues: Replaying events lets you reconstruct the exact state of an entity at any past point in time.
  • CQRS Architectures: The event stream naturally feeds multiple independent read-model projections tailored to different queries.

State-Based Persistence

  • CRUD Admin Panels: Simple direct reads and writes against current data are sufficient and avoid the overhead of replay logic.
  • High-Write Simple Entities: Avoids unbounded log growth for entities with frequent, low-value updates like counters or status flags.
  • Ad-hoc Reporting: Analysts can run SQL directly against current-state tables without building and maintaining projections.