background preloader

CQRS and Event Sourcing

Facebook Twitter

Why use Event Sourcing? Udi and I agree on probably 95% of what we talk about, one of the places that we have differing opinions is in the use of Event Sourcing I use the term as described previously to mean the rebuilding of objects based on events, not the definition that is currently on the bliki.

Why use Event Sourcing?

To me this is an important distinction and I figured it would be worthwhile to write a post on why I feel the way I do, I explained parts of it in the previous post about CQRS and Event Sourcing but I wanted to talk not just about how the patterns are symbiotic but also some of the other reasons I use event sourcing. Using a RDBMS. Race Conditions Don’t Exist.

Bryan Wheeler, Director Platform Development at msnbc.com “Udi Dahan is the real deal.

Race Conditions Don’t Exist

We brought him on site to give our development staff the 5-day “Advanced Distributed System Design” training. The course profoundly changed our understanding and approach to SOA and distributed systems. Consider some of the evidence: 1. Months later, developers still make allusions to concepts learned in the course nearly every day 2. One of our developers went home and made her husband (a developer at another company) sign up for the course at a subsequent date/venue 3. If I were to do the whole thing over again, I’d start the week by playing the clip from the Matrix where Morpheus offers Neo the choice between the red and blue pills. Beyond the training, we were able to spend some time with Udi discussing issues unique to our business domain. Sam Gentile, Independent WCF & SOA Expert “Udi, one of the great minds in this area.A man I respect immensely.” Clarified CQRS. After listening how the community has interpreted Command-Query Responsibility Segregation I think that the time has come for some clarification.

Clarified CQRS

Some have been tying it together to Event Sourcing. Most have been overlaying their previous layered architecture assumptions on it. Here I hope to identify CQRS itself, and describe in which places it can connect to other patterns. Download as PDF – this is quite a long post. Why CQRS Before describing the details of CQRS we need to understand the two main driving forces behind it: collaboration and staleness. Collaboration refers to circumstances under which multiple actors will be using/modifying the same set of data – whether or not the intention of the actors is actually to collaborate with each other.

Staleness refers to the fact that in a collaborative environment, once data has been shown to a user, that same data may have been changed by another actor – it is stale. A picture for reference. When to avoid CQRS. Bryan Wheeler, Director Platform Development at msnbc.com “Udi Dahan is the real deal.

When to avoid CQRS

We brought him on site to give our development staff the 5-day “Advanced Distributed System Design” training. The course profoundly changed our understanding and approach to SOA and distributed systems. Consider some of the evidence: 1. Months later, developers still make allusions to concepts learned in the course nearly every day 2. One of our developers went home and made her husband (a developer at another company) sign up for the course at a subsequent date/venue 3. Greg Young Discusses State Transitions in Domain-Driven Design and DDD Best Practices. 2.

Greg Young Discusses State Transitions in Domain-Driven Design and DDD Best Practices

Can you tell us a bit about how you are using Domain-Driven Design and use cases of DDD? Our main domain is an in-memory model representation of what the stock market is in the current state of and as it changes - that would be our domain. Our strategies all run within this domain, doing various things. Event Sourcing. Capture all changes to an application state as a sequence of events.

Event Sourcing

We can query an application's state to find out the current state of the world, and this answers many questions. However there are times when we don't just want to see where we are, we also want to know how we got there. Event Sourcing ensures that all changes to application state are stored as a sequence of events. Asynchronous Event Sourcing using Actors. We Recommend These Resources Introduction There has been some discussions lately about Event Sourcing.

Asynchronous Event Sourcing using Actors

For example, Greg Young recently discussed how they were using Event Sourcing and explicit state transitions together with Domain-Driven Design (DDD) to build a highly scalable and loosely coupled system. So what is Event Sourcing? Martin Fowler wrote an excellent article about some years ago and there is no use repeating it here, so please read (or at least skim) that article before reading further.

CQRS-FAQ - home. Event Sourcing and CQRS, Let's use it. Last time, we started a very basic Event Sourcing/Domain Events/CQRS framework.

Event Sourcing and CQRS, Let's use it.

Be careful, I made an edit in the nested DomainEvents+Handler<T>.Handles<E>() method, the AggregateRoot.Replay method will not work as is, but we won’t need it. We’ll build an equally simplistic application for personal library management. The Ubiquitous Language will be minimal. A Book can be Registered with a Title and an ISBN. A Book can be Lent to a Borrower at some Date for an Expected Time Span.

Choices