System design · interactive
CQRS and event sourcing
Instead of storing the current balance and overwriting it, store every change as an event that never changes. Current state is what you get by replaying them. Different read models can be built from the same events. Drag back in time.
Event store (append-only)
- Mar 1AccountOpenedowner: Ada
- Mar 2MoneyDeposited+100
- Mar 5MoneyWithdrawn−30
- Mar 9MoneyDeposited+250
- Mar 12MoneyWithdrawn−80
- Mar 15AddressChangedLahore
- Mar 20MoneyWithdrawn−40
Read models, rebuilt from the events
Balance
$200
Deposits
2
Total withdrawn
$150
Address
Lahore
Replaying 7 events, the account stood at $200 on Mar 20. Nothing was overwritten, so any past state can be rebuilt and every change is audited.
1 Each event records something that happened. Events are never updated or deleted.
A full audit log for free.
2 3 4
In production
Tools and technologies
Event stores and stream processors make this practical.
Not tied to one language — use these names when you search docs or design a system.