Event Sourcing Primer
What Is Event Sourcing?
Event Sourcing stores state as a sequence of events rather than as a current snapshot. Instead of updating a row in a database, you append an event describing what happened.
The Core Pattern
Command → Decide → Events → Evolve → State- A command expresses intent (“Add item to cart”)
- The decide function checks business rules against current state
- On success, it produces events (“Item was added”)
- The evolve function applies events to produce new state
- The new state is available for the next decision
Why Events?
- Audit trail: Every state change is recorded
- Time travel: Replay events to reconstruct any historical state
- Decoupling: Other systems react to events, not commands
- Debugging: The exact sequence of facts is always available
Why Formal Verification?
Runtime frameworks check correctness through tests. Weltenwanderer checks correctness through proofs.
The evolve function — a left-fold over events — is structurally a finite automaton when the state type is finite. All properties of finite automata are decidable. The compiler exploits this to verify exhaustiveness, consistency, and postconditions without executing code.
Architecture Decisions
- ADR-005: Evolve as F-algebra with catamorphism fold
- ADR-008: Rejection is not an event
- ADR-009: Multi-event atomic application with left-fold
Further Reading
- Introduction — What Weltenwanderer does
- Quick Start — Write your first bounded context
- Decider Reference — Full decider syntax