Distributed patterns / Advanced / 5 min / Updated
Event sourcing and CQRS: replay the log, rebuild read models
Store every change as an event, build read models from the log, ship a bug and rebuild. Compare with CRUD, watch projection lag and snapshots.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
What is event sourcing?
Event sourcing stores every change as an event; CQRS builds separate read models from that event stream.
Why does it matter?
You get full history, audit, and the ability to rebuild or add views by replaying events.
What is the trade-off?
More moving parts: read models lag behind writes, events need versioning, long streams need snapshots.
How do you explain it in an interview?
"Ledger as an event log with snapshots; balance and statement views as projections we can rebuild."
Check yourself
In event sourcing, what is the source of truth?
Answer: The append-only log of events. Current state is derived by replaying events; read models can be dropped and rebuilt.
What does CQRS separate?
Answer: The write model (commands, events) from read models built for queries. Each read model is shaped for its queries and updated from the event stream.
Why take snapshots?
Answer: So a rebuild replays only events since the last snapshot, not the whole history. Replaying millions of events takes minutes; snapshots cut it to seconds.