# Event Store

> Use a specialized database optimized for storing and retrieving event streams.

- **Category**: Event Driven Architecture
- **Subcategory**: core
- **Canonical URL**: https://designpattern.fyi/patterns/event_store/

---

## Description
**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.

**Problem**: Where and how should events be stored for event-sourced applications?

**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.



## Use Cases
Use as the persistence mechanism for event-sourced applications where you need both event storage and event-based pub/sub.





## Trade-offs


### 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




### Considerations & Drawbacks

- 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







---
**Reference**: [Original Source](https://microservices.io/patterns/data/event-sourcing.html)

