State as a story
Most systems store current state and overwrite it on every change. Event sourcing flips that: it stores an append only log of events that describe everything that happened, and derives current state by replaying them.
Instead of saving an account balance, you save events like money deposited and money withdrawn. The balance is whatever you get by folding those events together.
Why bother
- Full audit comes for free, since the log is the complete history.
- Time travel lets you rebuild the state as of any past moment.
- New views can be built later by replaying the same events differently.
The hard parts
Events are facts that already happened, so they are immutable. You never edit an old event; you append a new correcting one. Replaying a long log is slow, so systems periodically save a snapshot of state and replay only events after it. Changing the meaning of old events over time, called schema evolution, takes real discipline.
Event sourcing pairs naturally with read models that are kept up to date as events arrive.
Key idea
Event sourcing keeps an immutable log of facts and derives current state by replaying it.