Questions tagged [cqrs]

Command-Query Responsibility Segregation (CQRS) is an architectural pattern which separates commands (that change the data) from queries (that read the data). See 'about cqrs tag' for more details and references to learning materials. Not to be confused with Command-Query Segregation ([CQS]), a principle of object method design which CQRS incorporates.

The Command-Query Responsibility Segregation (CQRS) principle, in its core form, merely introduces separation of reads from writes. This simple approach brings the following benefits:

  • denormalized query persistence is optimized for the reads (which usually make up the most of the persistence I/O) resulting in better performance and user experience;
  • we can optimize our read side for the needs of the UI (for example, fetching the dashboard for the user in a single query) which will result in better development experience and less risk of breaking something on the write side.
  • read side can be put on some cloud storage, which is inherently optimized for the reads, could be partitioned, replicated and even distributed via a CDN;
  • by offloading data reads to synchronous queries we automatically increase the performance of the write side - now it has lower stress and lower probability of hitting a deadlock (which you should still account for).

Deeper introduction and more learning materials are available for study in CQRS Starting Point.

What about things that you hear in any CQRS talk: commands, events, DDD, eventual consistency and almost-infinite scalability? These are distinct architectural patterns with their own benefits and peculiarities. These patterns play so nicely with the CQRS principle (separation of reads from the writes), that they are often perceived as one thing.

So when we say "CQRS" this often means: "CQRS Principle" + "Message-driven architecture with commands, events and queries" + "Domain-Driven Design Methodology". This combination is one of the most frequent variations of "CQRS Architecture" (sometimes Event Sourcing is included there by default as well). Success of this variation is the reason why there is so much buzz and hype around the original CQRS term.

So here's what we have here:

  • CQRS - buzzword that could mean a lot of things.
  • CQRS Principle - principle that dictates separation of reads from writes in your system.
  • CQRS Architectures - specific architectural designs based upon the CQRS Principle and a few other time-proven methodologies and approaches. They usually come with a clear evolution path enabling migration of live application to more elaborate design, if needed.
  • DDDD (Distributed Domain-Driven Design) - one of the CQRS Architectures, as presented by Greg Young. It is based upon "CQRS Principle" + "DDD" + "Message-based architecture" + "Event Sourcing".

Not to be confused with Command-Query Segregation (), a principle of object method design which CQRS incorporates.

References

1943 questions
33
votes
6 answers

How to Command Query Responsibility Segregation (CQRS) with ASP.NET MVC?

I have been reading about Command Query Responsibility Segregation (CQRS). I sort of wonder how would this work with ASP.NET MVC? I get the idea of CQRS conceptually it sounds nice and sure does introduce some complexities (event and messaging…
Jeff
  • 13,079
  • 23
  • 71
  • 102
33
votes
5 answers

CQRS - The query side

A lot of the blogsphere articles related to CQRS (command query repsonsibility) seperation seem to imply that all screens/viewmodels are flat. e.g. Name, Age, Location Of Birth etc.. and thus the suggestion that implementation wise we stick them…
user53791
33
votes
5 answers

What is an example of a task based UI?

My team has been "tasked" to create an application that follows the task-based UI (not necessarily with CQRS). I really like a UI that helps the user accomplish common tasks easily, but many pieces of this application really "feel" (to me) like a…
Byron Sommardahl
  • 12,743
  • 15
  • 74
  • 131
32
votes
2 answers

What difference between NEventStore and EventStoreDB

Recently I'm learning CQRS and want to change my system to use event-sourcing patterns. But I found that on .Net platform, there is two Event Store implementations. NEventStore(formerly JOliver EventStore) EventStoreDB(from EventStore.com) The two…
JasonMing
  • 561
  • 8
  • 16
31
votes
2 answers

When to use an Eventstore

I am not quite sure I understood what an Eventstore is, I thought of it as some kind of "Transactionlog" for Domainobjects. What are the advantages/disadvantages of it and what are good scenarios to use it and when shouldn't it be used? EDIT: Since…
Bernhard Kircher
  • 4,132
  • 3
  • 32
  • 38
31
votes
2 answers

Does validation in CQRS have to occur separately once in the UI, and once in the business domain?

I've recently read the article CQRS à la Greg Young and am still trying to get my head around CQRS. I'm not sure about where input validation should happen, and if it possibly has to happen in two separate locations (thereby violating the Don't…
stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
30
votes
8 answers

Implementing Generic Interface in Java

I have a Java generics question I was hoping someone could answer. Consider the following code: public interface Event{} public class AddressChanged implements Event{} public class AddressDiscarded implements Event{} public interface Handles
whistlenuts
  • 517
  • 1
  • 5
  • 11
29
votes
2 answers

How to instantiate Mediatr as part of a Unit Test?

I am trying to build an xUnit Test project for an MVC Core 2.2 Application that is based on the CQRS/ES pattern. I utilize MediatR as part of my CQRS/ES pattern in the MVC application. In one of my commands which I would like to test, I inject…
Roland
  • 437
  • 1
  • 4
  • 7
29
votes
2 answers

Inter-Aggregate Communication in CQRS + DDD + Event Sourcing

How should separate aggregate roots (AR) communicate with one another in an environment built on DDD principles using an event-sourced aggregate back-end? For instance, I have a Facility aggregate root (AR) which has a factory method responsible for…
JD Courtoy
  • 2,855
  • 25
  • 27
29
votes
5 answers

How to adapt CQRS to projects?

I came across a new term named CQRS (Command Query Responsibility Segregation) which states that the conceptual model should be split into command model and query model as a typical CRUD model in which the command and query happens in the same…
Jack
  • 7,433
  • 22
  • 63
  • 107
28
votes
4 answers

CQRS - is it allowed to call the read side from the write side?

I started with reading about CQRS and I'm little confused. Is it allowed to call the read side within the write side for getting additional informations? http://cqrs.nu/Faq/command-handlers here they say it is not allowed, but in the cqrs journey…
Thomas Geulen
  • 590
  • 7
  • 22
27
votes
3 answers

Event Sourcing Resources

Looking for some suggestions for useful discussion groups, articles, success stories, reference apps, and tooling (.Net) on the subject of event sourcing. I am already familiar with: Fowler's article:…
Phil Sandler
  • 27,544
  • 21
  • 86
  • 147
27
votes
1 answer

CQRS: Storing events and publishing them - how do I do this in a safe way?

As I've learned in Why is the CQRS repository publishing events, not the event store? it's the CQRS repository's task to publish events. So far, so good. Of course, storing the events and publishing them should be within one single transaction.…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
26
votes
4 answers

Domain queries in CQRS

We are trying out CQRS. We have a validation situation where a CustomerService (domain service) needs to know whether or not a Customer exists. Customers are unique by their email address. Our Customer repository (a generic repository) only has…
JontyMC
  • 6,038
  • 6
  • 38
  • 39
25
votes
1 answer

Axon Framework vs Eventuate comparison

We are currently doing some research about CQRS and Event Sourcing and found two major frameworks taking care of these two concerns: Axon Framework and Eventuate. Both are continuesly developed, while Eventuate is now more actively developed in the…
Stefano L
  • 1,486
  • 2
  • 15
  • 36