vishal patel
LearningAdvancedUpdated 2026-09-23

Event Sourcing

Store every state change as an immutable event; current state is derived by replaying events. The log is the source of truth.

auditeventstemporal-queriesimmutability

The idea

Instead of UPDATE account SET balance = 70, append MoneyWithdrawn {amount: 30}. The balance is a fold over all events. Nothing is ever overwritten.

diagram

Key mechanics

  • Streams per aggregate (release-123), with optimistic concurrency on the expected version.
  • Snapshots every N events so loading stays fast.
  • Upcasting or versioned events, because old events live forever and schemas evolve.
  • It almost always comes with CQRS, since you can't query an event log efficiently.
Use it when
  • Audit and history are core requirements (finance, compliance, content versioning)
  • You need 'what did this look like on date X?'
  • Business insight from behaviour over time is valuable
Avoid it when
  • Simple CRUD domains
  • The team is new to event-driven design
  • You need frequent ad-hoc queries on current state without projections

Trade-offs

  • ✅ A perfect audit trail, time travel, debugging by replay, and new projections from history.
  • ❌ Event schema evolution is hard and permanent.
  • ❌ GDPR-style deletion needs patterns like crypto-shredding.
  • ❌ A steep learning curve, and it's easy to over-apply.
Note

Content versioning in a CMS is a lighter cousin of this: every save creates a new version you can compare and roll back to. Full event sourcing goes further and makes the change log the primary store.

Sources & further learning

Videos, courses, docs and books I recommend for this topic.

Related topics