Event Sourcing Patterns
Capture every state change as an immutable event. Rebuild state by replaying the log.
Core Idea
Instead of storing current state in a row, persist a sequence of events. The aggregate root replays events to reconstruct its state. This gives you a full audit trail, temporal queries, and easy debugging.
Event Store
Append-only. Events are keyed by aggregate ID and version. Use optimistic concurrency with a version check to prevent conflicts. Never mutate or delete events.
Projections
Build read models by subscribing to events. Projections transform the event stream into query-optimized views. Keep them disposable — you can rebuild from the event log at any time.
Snapshots
For long-lived aggregates, periodically snapshot state at a version. On load, replay only events after the snapshot. Trade storage for faster hydration.
Meridian tip: Use event sourcing when auditability matters — billing, inventory, compliance workflows. Pair with CQRS for read-heavy workloads.