October 17, 2022
Event sourcing as an application architecture pattern is rising in popularity. Event sourcing involves modeling the state changes made by applications as an immutable sequence or “log” of events. Instead of modifying the state of the application in-place, event sourcing involves storing the event that triggers the state change in an immutable log and modeling the state changes as responses to the events in the log. We previously wrote about event sourcing, Apache Kafka and how they are related. In this post, I explore these ideas further and show how stream processing and, in particular, Kafka Streams helps to put Event sourcing and CQRS into practice.
There’s a number of great introductory articles, so this is going to be a very brief introduction. With event sourcing, instead of storing the “current” state of the entities that are used in our system, we store a stream of events that relate to these entities. Each event is a fact, it describes a state change that occurred to the entity (past tense!). As we all know, facts are indisputable and immutable.
Having a stream of such events it’s possible to find out what’s the current state of an entity by folding all events relating to that entity; note, however, that it’s not possible the other way round — when storing the “current” state only, we discard a lot of valuable historical information.
- Thinking in Events Unlimited
- The Real World Modelled in Software Unlimited
- State-Based vs. Event-Based Systems Unlimited
- Illustrating Event-Based vs. State-Based Systems with Chess Unlimited
- Setting Up Confluent Cloud Unlimited
- Storing Data as Events Unlimited
- Classic CRUD: Create, Read, Update, and Delete Unlimited
- Event Sourcing: Create and Read Only Unlimited
- Getting Current State Unlimited
- Event Sourcing Preserves Everything Unlimited
- Event Sourcing in Practice Unlimited
- Why Store Events Unlimited
- Event Sourcing is Evidentiary Unlimited
- Events are Recoverable Unlimited
- Event Data is Insightful Unlimited
- Hands On: Trying Out Event Sourcing with Confluent Cloud Unlimited
- Event Sourcing vs. Event Streaming Unlimited
- CQRS with Data in Motion Unlimited
- CQRS Applied to Microservices Unlimited
- Progressing to Event Streaming Unlimited