If Event sourcing is new to you, then before further reading, I recommend that you study at least some of the videos from the list below:
- Anuar Nurmakanov — Event Sourcing and CQRS on a specific example
- Yakov the Cook — Introduction to Event sourcing
- Event Sourcing You are doing it wrong by David Schmitz – I like the fact that various variations of the implementation are described
- Event sourcing meetup with Alexey Zimarev and Greg Young – a classic presentation from Greg Young (in many ways the popularizer of the term)
- Opening Keynote: Greg Young - Stop Over-Engineering
- Designing Events-First Microservices
- Go Back to the Future with Event Sourcing and CQRS
- Event-Driven Architectures for Spring Developers
- Event Sourcing - what could possibly go wrong? • Andrzej Ludwikowski • Devoxx Poland 2021
- Building Event-Driven Microservices with Event Sourcing and CQRS - Lidan Hifi
- The Power of Event-Driven Systems without Burning your Hands or Budgets • Allard Buijze • GOTO 2020
Short description
Event sourcing is an architectural principle. It differs slightly in different interpretations. Let’s introduce definitions to speak the same language:
Commands
are accepted to change the data. For example, registerUser. The command may respond with an error if it considers that it is impossible to execute. The command generates 1+ `events'.Events
are a fait accompli. They are stored separately, for example, in some kind of table in the database. Or in Kafka. For example, UserRegistered. Let’s call the storage the `event store'.Aggregate
is the central term of transactionality. Each event is linked to it. For example,User(GUID="....")
. It can be seen that the aggregate usually has a type (user
) and an id (guid
).- When reading data, sometimes an aggregate is created in memory, events are scrolled in it - thus getting the current state of the aggregate - and giving it in the desired form. This is called a `live projection’. It sounds strange at first glance, but with an aggregate size of up to 20 events, it works almost instantly.
- And sometimes a regular database optimized for reading is used. It is called a
projection'. Potentially, there may be several such databases (for example, Elasticsearch for full-text search and Postgres for regular queries). Usually one of them is called the
main projection'. - To make projections, there are handlers that listen for the appearance of new events. They are called `projectors'.
- If the projectors work synchronously with the addition of new events, then these are
inline projectors'. Otherwise, they are
asynchronous projectors'. - For side effects (communication with external systems, creation of secondary events) there is a separate type of handlers - `reactors'.
Projections can be divided into 3 types:
- inline projections - runs as part of the command receiving mechanism
- asynchronous (async) projections - work as a background process (and therefore with delays)
- live projections - no additional storage is used, they are calculated dynamically from events
Event sourcing goes well with “CQRS”. In fact, event sourcing is a continuation of CQRS inside the backend of the application, including the database. Therefore, sometimes they are not distinguished, but they are different things.
Someone implements event sourcing in part of the application, someone completely.
I note that there are many variations to the scheme above, because this is a principle, and not even a specific architecture.
Examples of implementations
Commercial engines:
Open source engines:
- https://www.sequent.io/
- https://railseventstore.org/
- https://github.com/digital-fabric/ever
- https://github.com/envato/event_sourcery
- https://martendb.io/events/
- https://github.com/commanded/commanded / https://github.com/commanded/eventstore
- https://github.com/cultureamp/kestrel
- https://github.com/cultureamp/event_framework
- https://occurrent.org/
Open source application templates:
- https://github.com/isalevine/event-sourcing-user-app
- https://github.com/nicusX/kotlin-event-sourcing-example
1C
It is not immediately obvious that 1C is the most popular event sourcing solution. It’s no wonder - there is intensive work with people and money, which means that a story is needed.
Document log – event store. Registers are projections. Etc .