State as a sum of events
Most systems store the current state of a record and overwrite it on every change. Event sourcing flips this. It stores an append only sequence of events that describe each change, and the current state is computed by replaying them.
How it works
- Every change becomes an immutable event such as money deposited or money withdrawn.
- Events are appended to a stream, never updated or deleted.
- To get the current balance you fold all events for that account from the start.
What you gain
- Full audit trail because no history is lost.
- Time travel since you can rebuild the state as of any past moment.
- New read shapes by replaying the same events into a different view.
What it costs
- More complexity than a simple update in place.
- Replay cost that grows with history, which snapshots later help with.
Key idea
Event sourcing keeps the full list of changes as immutable events and derives current state by replaying them.