What is an Event Store?¶
An event store is a database designed specifically to persist events permanently and immutably. While traditional databases are optimized to keep the current state of data, an event store takes a different approach: it preserves the entire history of events that led to the current state.
Current State vs. Event History¶
The key difference between an event store and a conventional database lies in how data is modeled and stored:
- Traditional databases usually record only the current state of an entity. Past states are overwritten or require explicit versioning to be preserved.
- Event stores record every event as an individual fact. The current state can always be reconstructed by replaying all events in their original order.
Example:
- In a relational database, an account balance might be stored as a single number.
- In an event store, every deposit and withdrawal is stored as a separate event. The balance is calculated by aggregating all those events.
Characteristics of an Event Store¶
Event stores share several defining properties:
- Append-only storage: Events are only ever added, never overwritten or deleted.
- Immutability: Once persisted, events remain unchanged.
- Chronological order: Events are strictly recorded in the order in which they occur.
- Replay capability: The current state – or any past state – can be reconstructed by replaying events.
- Auditability: Because nothing is lost, the event history forms a complete and verifiable audit trail.
Why This Matters¶
Using an event store provides several advantages:
- Traceability: Every change in the system is documented and can be inspected later.
- Flexibility: New read models or projections can be built at any time from the event history.
- Resilience: Systems can be rebuilt or corrected by replaying events.
- Integration: Events can be shared with other systems to trigger workflows or integrate processes.
Event Store vs. Event Log¶
An event store is sometimes confused with a simple event log. While both keep events in chronological order, there are important distinctions:
- An event log (such as in a message broker) is primarily a communication mechanism for distributing messages.
- An event store is a full-fledged database, providing not just messaging but also durable storage, querying, snapshots, and replay capabilities.
Conclusion¶
An event store is therefore much more than just a sequence of logged events. It is the foundational building block of event sourcing, because it captures a system's business history in a complete and durable way. Anyone adopting event sourcing will need a persistence mechanism that reliably delivers on these requirements.
Next up: Why Database Choice Matters – why choosing the right database is critical for event sourcing.