How it works · 20 of 49 Advanced

What is event sourcing?

Store what happened, not just the result

Event sourcing: Event sourcing stores every change as an event in an append-only log ("salary in ₹50,000", "rent out ₹18,000") and works out the current state by replaying the log, instead of overwriting one row. You get the full history, the state on any past day, and corrections that show as new events rather than edits. The price: the log is never edited, so event formats must be versioned; long logs need snapshots to replay fast; replays must not resend emails or payments; and it is costly to adopt or undo.

Loading the animation…

Say it like this Event sourcing stores every change as an event in an append-only log and computes the current state by replaying it, so you keep the full history and the state on any past day, at the price of versioned events, snapshots and more complexity.

Under the hood — for builders
The sources, in their words
Martin Fowler ("Event Sourcing", 2005): "Capture all changes to an application state as a sequence of events"; "We can determine the application state at any point in time." Microsoft ("Event Sourcing pattern", 2026): "The only way to update an entity or undo a change is to add a compensating event."
What the log can answer
Event: a fact that happened, named in the past tense ("rent out"). Append-only: lines are added at the end, never changed. Compensating event: a new line that reverses an earlier one.
Run here: why snapshots
Snapshot: the state saved at a point in the log, so a replay starts there (the passbook's "brought forward"). Time to rebuild one balance from 1,000,500 stored events:
Changing an event's shape
The log is never edited, so old events keep their old format forever. Microsoft lists four ways to cope, safest first:
Replays and side effects
Fowler: if events send "update messages ... to external systems" during a replay, "things will go wrong"; switch those gateways off while replaying.
Measure it
Events per stream · replay time with and without a snapshot · projection lag · events written in an old format.
Watch out
Microsoft: "For most systems and most parts of a system, traditional data management is sufficient." Personal data in an append-only log clashes with deletion laws; keep it outside, referenced by id.
Sources
Martin Fowler, "Event Sourcing", 2005 · Microsoft, "Event Sourcing pattern", Azure Architecture Center, 2026 · both read in session · SQLite replay run, Python, 19 Nov 2026.

What happens in the event sourcing animation, step by step?

  1. Most systems store only the result: one balance, overwritten on every change. Last week's balance is gone.
  2. Event sourcing stores what happened instead: every line, in order, never edited.
  3. The balance is the lines replayed, one by one. Same answer, and nothing was lost.
  4. Your turn: drag the date back, below the picture. The balance on any past day.
  5. The card fee was charged by mistake. The line is never erased: a new line reverses it, and the history shows both.
  6. Long logs replay slowly, so keep a snapshot and replay only what follows. Next: saving a change and announcing it, both or neither.

What everyday example explains event sourcing?

A passbook, not just a balance. Every line stays; the balance on any date is the lines added up to that date.

Why should a team care about event sourcing?

Where the history is the product (ledgers, orders, bookings, audits) a state-only table throws away what a regulator or a bug hunt needs. Elsewhere it is complexity you will pay for every day; apply it to one part, not the whole system.