Event Sourcing and Event-Driven Architecture — In Under 5 Minutes!

Erçin Dedeoğlu
6 min readOct 3, 2022

--

Event sourcing and event-driven architecture are two software techniques that have repeatedly popped up on my radar in my career. It starts with the basic definition of both terms; then, we see how they can complement each other in a project.

In this story, you will discover how Event Sourcing relates to Event-Driven and why these two approaches are seen as alternatives or competitors.

Events are the building blocks of all web applications. When we think about web applications, we tend to think of them as user interactions or API calls that change something in the database. But another kind of “event” happens in a web application: events from external sources such as text messages, emails, push notifications, or phone calls. These events have their unique challenges and requirements for persistence and processing.

Event-Driven

Event-driven architecture is a general pattern that uses events to trigger actions. The most common implementation of this pattern is Event Sourcing, which uses events as the source of truth for data storage.

Event Sourcing may be best suited for use cases where more than one person needs to read from the same dataset, and all changes must be stored in an append-only fashion to be audited and analyzed later on.

Event Sourcing

Event sourcing is a pattern for persisting the history of changes to an application’s state. Data is stored as a series of events, capturing a snapshot of the application’s condition. The possibilities are stored and managed in an event store, which may be implemented with various technologies. The identifier for each event identifies it as unique among all other events; its properties represent what has happened since the last one was added (e.g., “Alice bought milk”).

In this way, you can use event sourcing to replay past states of your application by replaying all previous events. This feature can be helpful when debugging or recovering from failure scenarios.

Event Sourcing vs. Event-Driven

Event Sourcing is a technique used to implement the event-driven architecture. It’s a form of data persistence that stores the history of events in the system rather than keeping its current state.

Event Sourcing has three distinct advantages over traditional approaches to data storage:

  • Transactions are immutable and recorded as a sequence of events, making it easier for you to understand what happened and when.
  • Events can be replayed at any time if needed, even years later! This makes debugging much simpler because you can easily step back through your code base until you find out where things went wrong (if they did).
  • Event sourcing is often combined with CQRS (Command Query Responsibility Segregation), which allows different parties or applications access only to certain types of operations without compromising integrity or consistency between them — this means less manual synchronization between teams or groups within an organization!

Takeaway

With Event Sourcing, you can think of the state of your application as a series of events. In this way, you can see that if one event has happened, all other events will have occurred too. The event store acts like a logbook for your system. Other components will use this log book to determine what should happen next (in terms of business logic).

You might ask yourself: “What does Event Sourcing have to do with CQRS?” It’s simple: Event sourcing helps you implement CQRS.

Pros

Event-Driven Architecture:

  • Suitable for systems that have high throughput and latency requirements.
  • For example, a system must process web requests as quickly as possible.

Event Sourcing:

  • Event Sourcing is a good fit for systems that need to maintain historical data and audit trails.

Cons

Event sourcing is more complex, expensive, and less flexible than event-driven systems. Event stores are usually mutable, making it harder to understand the procedure and make changes. In addition, event sourcing requires a longer development time since you need to rewrite your application from scratch rather than simply adding new features. Event-driven applications are also easier to scale because they don’t require as much overhead as event sourcing.

Uses of Event-Driven Architecture

Event-driven architecture can be used in a variety of ways. It’s not specific to any application or product; you can implement it however you like. For example, suppose you’re looking for an architectural pattern to help you build loosely coupled applications without worrying about your data model changing too often. In that case, event-driven architecture is a great choice.

Event sourcing is just one specific way of implementing the event-driven architecture. Event sourcing focuses on capturing all the events that occur in your system as immutable facts (or “facts”) and using those facts as inputs or outputs from commands or queries instead of storing their current values every time they change (i.e., inserting/updating). This allows us to query backward through time and make predictions based on historical data points instead of just relying on live ones — which is especially important when dealing with large amounts of data!

Uses of Event Sourcing

Event Sourcing is a software design pattern where the state of an application is stored as a series of events. Event sourcing can be used in applications that track changes over time, such as financial transactions or user activity.

Event sourcing is similar to the CQRS pattern (Command Query Responsibility Segregation) and DDD’s Aggregates, but with differences:

  • Events are persisted on disk instead of snapshots. The reason for this is that snapshots create inefficient queries that require complex joins and other operations.

Event-driven architecture is a general pattern, and event sourcing is one specific implementation

Event-driven architecture is a general pattern, and event sourcing is one specific implementation. This means that event-driven architecture can be used without event sourcing, but it’s not the same. Likewise, you can use event sourcing without implementing an event-driven architecture.

Even though they are not synonymous, both patterns have benefits and drawbacks that make them useful in different contexts.

Conclusion

In conclusion, event sourcing and event-driven architecture are two different things. Event sourcing is a specific implementation of the general pattern of event-driven architecture. The key takeaway is that they are not mutually exclusive but complementary and can be used together to achieve their respective benefits.

I wrote a series of articles on software architecture. Maybe it will interest you?

My other publications: https://ercindedeoglu.github.io/

--

--

Erçin Dedeoğlu
Erçin Dedeoğlu

Written by Erçin Dedeoğlu

I am passionate about solving problems and developing products to make people’s lives easier.

Responses (4)