Microservices - Is event store technology (in event sourcing solutions) shared between all microservices?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Microservices architecture revolutionizes the way enterprises build their IT infrastructures, affording them scalability, flexibility, and robustness. An important pattern in modern microservices architectures is Event Sourcing, closely associated with Event Store technology. This discussion delves into what Event Store technology is, how it operates within microservices, and whether it should be shared between microservices.
What is Event Sourcing?
Event Sourcing is a design pattern where changes to the state of an application are stored as a sequence of events. Instead of storing just the current state of the data in a domain, Event Sourcing involves storing the history of each state change as an event. This can allow systems to better understand the sequence of actions, simplify tasks in distributed systems like auditing, and facilitate event replay to restore historical states or support debugging.
The Role of Event Store in Event Sourcing
An Event Store acts as the storage mechanism for the events in an Event Sourcing-based system. It is fundamentally a database optimized for the append-only storage of events. These events are stored in a sequence, and can be queried or processed asynchronously by different parts of an application or by different applications entirely.
Microservices and Event Store: Shared or Isolated?
In a microservices architecture, different services are meant to be loosely coupled and independently scalable. Thereby, sharing an Event Store among multiple services might seem counterintuitive as it introduces a degree of coupling.
Arguments for Isolated Event Stores:
- Decoupling: Each microservice managing its own Event Store ensures services are as independent as possible, adhering to the microservices principle of decentralized data management.
- Security and Compliance: Isolated stores can be secured specifically according to the needs of the service, aligning closer with security best practices.
- Tailored Schema: Different services might have different requirements on the data events structure and having separate event stores allows for specific optimizations.
Arguments for a Shared Event Store:
- Simpler Infrastructure: Less complexity in managing multiple databases.
- Cost-Effectiveness: Consolidating infrastructure can reduce costs.
- Eventual Consistency: Easier to achieve as all events are in a single store, simplifying the process of maintaining consistency across bounded contexts.
Practical Implementation Choices
When implementing Event Sourcing in a microservices architecture, businesses often have to decide between shared or isolated Event Stores based on their specific needs. The choice largely depends on the scale of the system, the interdependencies between microservices, security considerations, and resource availability.
Example Scenario
Imagine a financial service application composed of three microservices: Transaction Handling, Account Management, and Reporting. Here's how the Event Store might be approached:
- Transaction Handling and Account Management: These might share an Event Store because they operate tightly around the transaction data and account states. Sharing can reduce duplication and maintain consistency between transactions and accounts.
- Reporting: This might use a separate Event Store. Reports often need to be detailed and involve complex queries which can be optimized in a separate store without impacting the performance of the transaction systems.
Key Points Summary
| Aspect | Shared Event Store | Isolated Event Store |
| Decoupling | Lower | Higher |
| Security/Compliance | Standardized | Customizable |
| Infrastructure | Simplified | Complex |
| Cost | Potentially Lower | Potentially Higher |
| Consistency | Easier | Challenging |
Conclusion
Deciding whether to share an Event Store amongst microservices or have it isolated depends heavily on the specific context and requirements of the application and organizational policies. With event sourcing, particularly in complex and highly regulated environments, achieving the right balance between autonomy and practicality is key to a successful implementation.

