Event Sourcing with CQRS

Zartis
Level Up Coding
Published in
10 min readMay 12, 2021

--

How to utilize CQRS and event sourcing together

Keith Redmond, VP of SaaS Engineering at Zartis, shares his insights on how to utilize Event Sourcing with CQRS in your application development.

This article was presented as a webinar as part of the ‘Talking .NET’ conference, you can see the full webinar here.

What is Event Sourcing?

Event Sourcing is an application design pattern that focuses on tracking operations as a sequence of events which are then aggregated to produce system state.

You can not only query these events, but also use the event log to reconstruct past states, and to automatically adjust the state to cope with retroactive changes.

First and foremost, it’s about how to design your application to focus on tracking not just what your data looks like, but why your data looks that way. What are the operations that created the data that you’re storing and what is the sequence of events that produced your system state?

What is CQRS?

Command Query Responsibility Segregation (CQRS) is an architectural pattern that splits applications that operate on/create data apart from those which read data.

It is important not to confuse CQRS with concepts such as Service-Oriented Architecture and microservices, it’s not really about the size of what we’re trying to do, it’s not about the size of the applications or their granularity, it’s really about the operations that they perform. And Event Sourcing isn’t trying to be a silver bullet. It’s not trying to replace every other solution, but there are ways in which it can be a good choice for your business.

Centralized State Database

To begin a discussion about a change towards Event Sourcing and CQRS, it’s important to understand the challenges with the more traditional or common approaches. One of the best examples for that would be the Centralized State Databases, and how operations in your system can change the state of our database.

So to take a pretty simple example — in the graph below we have a state database and at the top, there are four business operations that can change the state of that data:

--

--

We know good code. We are a digital solutions provider specialised in building cutting-edge software with bespoke development teams. www.zartis.com