Event sourcing is an architectural pattern that states that events, the changes, are captured and used as the source of data in a system. In Domain Driven Design there is a lot of emphasis on properly recognizing and designing business domains. With CQRS this emphasis is reinforced in a distinction between modifying (command side) and querying (query side) of each domain. Events then express the changes, the modifications, that are initiated by commands, according to the business domain. Thus, these events provide extensive possibilities for explicit translation and synchronization to all and varied views or projections. Event sourcing is therefore closely related to DDD and CQRS and these concepts reinforce each other.

Event Sourcing with multiple views

By applying event sourcing in combination with CQRS, a strong connection emerges between commands and actions ‘at the front end’ of a domain and the views ‘at the back end’. It supports and substantiates the understanding that ’the back end’ is not one view, but that there are multiple and different projections on the same set of changes of a domain. Compared to the current state of systems, this is a paradigm shift from ‘one model to commands, events and queries’.

Event Sourcing Paradigm Shift

Through this shift towards commands, events and queries, many possibilities arise:

  • The list of changes, the events, by definition form the ‘audit trail’ of the domain and the system. This substantiates very precisely why something happened, what the intention was, when it happened and by what or whom.

  • Historical data can be reproduced based on the list of events, to understand what happened, why and to restore the system to an earlier state.

  • Consistency in CQRS is challenging. The use of cloud infrastructure further reinforces the complexity in this. By handling the explicit list of events in order, as is common in event sourcing, keeping it consistent and also keeping track of the actuality per view becomes simple(r) and transparent(er). This offers enormous advantages and possibilities, also to vary per view and situation.

  • Improvement of business domain alignment because the business is forced to explicitly express what the changes are and what should be done with them. These then become direct and concrete instructions for the development teams. Business events and technical synchronization become aligned. Issues around synchronization, actuality and understanding become aligned between technology and business domain. Therefore, event sourcing is also recommended from Domain Driven Design.

References

Although [[event-sourcing]] is a common architectural pattern, there is no authoritative source that describes it. There are mainly different references that highlight and describe different aspects. These are strongly related to references about [[cqrs]] and [[domain-driven-design]]:

  1. AxonIQ Docs: AxonIQ is the company behind the Axon Framework; a Java framework for building Event Sourcing systems. Read for example:

  2. Greg Young: Greg Young is a pioneer in the field of CQRS and Event Sourcing and has shared a lot of knowledge in articles and videos. His insights often focus on practical implementation and challenges.

    • Search for “Greg Young Event Sourcing” for videos and presentations on YouTube or other platforms.
  3. For more understanding and inspiration about Event Sourcing I have tried to record a number of videos. These are published by my alter ego ‘Marc explains’ 😁

  4. Microsoft Docs (Event Sourcing): Microsoft has extensive documentation about Event Sourcing and the relationship with CQRS. They provide an overview of the advantages and disadvantages, and how you can implement the pattern:

  5. EventStore: EventStore is a popular database specifically designed for Event Sourcing. On their website you can find technical blogs and guides on how to apply Event Sourcing:

  6. Martin Fowler’s Blog: Martin Fowler is an authority when it comes to patterns and concepts. We therefore cannot omit this reference:

    • Event Sourcing - Martin Fowler

      warning this information from Martin Fowler is heavily outdated and is considered incorrect or no longer current by experts!

  7. Books:

    • “Implementing Domain-Driven Design” by Vaughn Vernon contains chapters on Event Sourcing in combination with DDD.
    • “Domain-Driven Design and Event Sourcing”* by Adam Dymitruk extensively discusses Event Sourcing in the context of DDD and CQRS.
  8. Community Resources & GitHub: On GitHub you can find various example projects that implement Event Sourcing in combination with CQRS and DDD, often in languages like Java, .NET, and Node.js.

These resources can give you an in-depth understanding and help you with practical examples and best practices to apply CQRS in your projects.