Event Store
Use a specialized database optimized for storing and retrieving event streams.
Intent & Description
⚠️ Problem
Where and how should events be stored for event-sourced applications?
📋 Context
You have applied the Event Sourcing pattern. Events need to be persisted and retrieved efficiently. The event store also needs to support subscribing to events so that services can react to new events in real-time.
💡 Solution
Use an Event Store—a specialized database optimized for storing and retrieving event streams. The event store provides an API for appending events to a stream (identified by an aggregate ID) and for reading all events for a given aggregate. It also acts as a message broker, providing a subscription API that enables services to subscribe to events and receive notifications when new events are appended. The event store guarantees that events are stored in the order they were appended and supports optimistic concurrency control to prevent conflicting updates. Examples include EventStoreDB, Axon Server, and custom implementations using databases with change data capture.
Real-world Use Case
Source
Advantages
- Optimized for append-only event storage with fast writes
- Built-in subscription mechanism eliminates the need for a separate message broker
- Supports optimistic concurrency control for conflict detection
- Natural audit log and temporal query support
Disadvantages
- Specialized technology with a smaller ecosystem than general-purpose databases
- Querying across aggregates requires projections or CQRS views
- Operational complexity of managing a specialized data store
- Vendor lock-in if using a proprietary event store solution