Design & Architecture

Event Sourcing

Advanced

Instead of storing only the current state and overwriting it on every change, event sourcing stores the full sequence of facts that happened — the events — and derives current state by replaying them. The events are the source of truth; the state is a projection. It is the purest expression of our immutability preference, and it gives you a complete, tamper-evident history for free.

A traditional system keeps one mutable row per thing and updates it: a balance goes from 100 to 80, and the fact that it was once 100 is gone. An event-sourced system instead appends immutable events — FundsDeposited, PaymentMade — and computes the balance by folding over them. Nothing is ever updated or deleted; you only ever append.

Event sourcing is powerful but not free: it changes how you query, how you evolve schemas, and how you onboard the team. Reach for it where the history is itself valuable — money movements, AML/KYC decisions, anything an auditor or regulator will later interrogate — and not as a blanket default for every CRUD screen. It pairs naturally with CQRS (events feed read models), Event-Driven Architecture, and Audit Trails, and it is the deep end of Mutable vs Immutable Design.

Model facts, append only

Mutating state, history lost account.Balance -= amount; // 100 -> 80
db.Update(account);
// no record of why, when, or that it was ever 100

The current number survives; the facts that produced it do not. You can never answer "how did we get here?".

Append a fact, fold for state store.Append(streamId, new PaymentMade(amount, payee, now));

// current balance is derived, not stored:
var balance = store.Read(streamId).Aggregate(0m, (b, e) => e.Apply(b));

Every change is an immutable fact. State is computed from facts, so the full history — and the reason for every number — is always recoverable.

Use it where history is the value

Operate it safely

Self-review checklist

Why it matters: In a regulated, money-handling system the question is rarely just "what is the balance now?" but "how did it get there, who decided, and when?". Event sourcing answers that by construction: an immutable, append-only log of facts is the strongest possible audit trail and lets you rebuild any past state or any new read model on demand. The cost — querying, schema evolution, erasure — is real, so apply it where the history pays for itself rather than everywhere.