Event sourcing
Description
Event-sourcing is the architectural move of treating the log of state-changing events as the source of truth, and deriving current state by replaying the log. The diagnostic shape: instead of storing “user X has $100 in their account,” you store “user X was credited $50 at t1, debited $20 at t2, credited $70 at t3” — and compute the current balance from the events on demand (or maintain a materialized view that’s rebuildable). The history is the data; the current state is a projection. The structural payoff is full audit trail by construction (you literally can’t have current state without having every event that produced it), temporal querying for free (“what did the balance look like on day 3?”), and rebuild-from-scratch for arbitrarily-new derived views (“we now want a per-month roll-up — rebuild from the log”). The cost is operational: replay time grows with log length, materialized views must be re-derived on schema changes, and the event schema becomes part of the contract. Event-sourcing is structurally the same primitive as filesystem journaling and database WAL — but inverted in emphasis. In journaling, the log is a recovery mechanism; the in-place state is the API. In event-sourcing, the log IS the API; the in-place state is an optimization.Triggers
User-initiated: User describes a system where the history of changes matters as much as current state — audit, regulatory, debugging, replay, what-if. Vocabulary cues: “event sourcing,” “CQRS,” “audit log,” “immutable log,” “log-as-truth,” “replay.” Agent-initiated: Engine notices a system that loses information when updating in place (overwrites destroy history) but where that history would be valuable. Candidate inference: “this wants event-sourcing — the events are the data, the current state is a view; consider treating the log as primary.” Situation-shape signals: Audit / regulatory requirement; need to answer “how did we get here?” queries; want to add new derived views without re-instrumenting; debugging a system where current state alone is insufficient.Exclusions
- Current state is all that matters — if no one ever asks “how did we get here?”, event-sourcing’s audit-by-construction is paying cost without earning benefit.
- Event schema changes too often — replaying old events through new handlers requires either versioned events or schema-evolution discipline; if the schema thrashes, event-sourcing’s “rebuild from log” becomes “migrate every event, then rebuild.”
- High-write-throughput with no value in history — every write is two writes (event + materialized view); the cost compounds.
- Privacy-sensitive data with right-to-be-forgotten requirements — immutable logs are structurally hostile to deletion; you need cryptographic shredding or a different architecture.
Structure
Relationships
- write-ahead-log — event-sourcing is WAL promoted to architectural status.
- eager-vs-lazy — materialized views vs on-demand replay is the eager-lazy choice applied per view.
- loop-completion — the log makes the journey legible; loop-completion gaps become diagnosable.
- saga — sagas need event-sourced substrate to replay compensations.
Examples
Git · computer-science
Git · computer-science
git checkout is replay.Accounting ledgers · economics
Accounting ledgers · economics
Apache Kafka as primary store · computer-science
Apache Kafka as primary store · computer-science
Audit logs in regulated industries · law
Audit logs in regulated industries · law
Blockchain · computer-science
Blockchain · computer-science
CRDTs (op-based) · computer-science
CRDTs (op-based) · computer-science
Helland, Pat (2015) "Immutability Changes Everything"; CQRS literature (Greg Young, Udi Dahan) · computer-science
Helland, Pat (2015) "Immutability Changes Everything"; CQRS literature (Greg Young, Udi Dahan) · computer-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 11 — modern stream-processing framing. · computer-science
Kleppmann, *Designing Data-Intensive Applications* (2017), Chapter 11 — modern stream-processing framing. · computer-science
Martin Fowler, "Event Sourcing" essay (2005), part of the eaaDev series at martinfowler.com/eaaDev/EventSourcing.html — the coining work that named and canonized the pattern. · computer-science
Martin Fowler, "Event Sourcing" essay (2005), part of the eaaDev series at martinfowler.com/eaaDev/EventSourcing.html — the coining work that named and canonized the pattern. · computer-science
OS file undo systems · computer-science
OS file undo systems · computer-science
Pacioli (1494) — accounting ledgers as the centuries-older instance. · economics
Pacioli (1494) — accounting ledgers as the centuries-older instance. · economics
Time-series databases · computer-science
Time-series databases · computer-science
Young, G., *CQRS Documents* (2010) — Command-Query Responsibility Segregation, the architectural sibling. · computer-science
Young, G., *CQRS Documents* (2010) — Command-Query Responsibility Segregation, the architectural sibling. · computer-science