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
315
votes
7 answers

Using Kafka as a (CQRS) Eventstore. Good idea?

Although I've come across Kafka before, I just recently realized Kafka may perhaps be used as (the basis of) a CQRS, eventstore. One of the main points that Kafka supports: Event capturing/storing, all HA of course. Pub/sub architecture Ability to…
Geert-Jan
  • 18,623
  • 16
  • 75
  • 137
134
votes
6 answers

Using an RDBMS as event sourcing storage

If I were using an RDBMS (e.g. SQL Server) to store event sourcing data, what might the schema look like? I've seen a few variations talked about in an abstract sense, but nothing concrete. For example, say one has a "Product" entity, and changes to…
Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
117
votes
5 answers

Difference between CQRS and CQS

I am learning what is CQRS pattern and came to know there is also CQS pattern. When I tried to search I found lots of diagrams and info on CQRS but didn't found much about CQS. Key point in CQRS pattern In CQRS there is one model to write (command…
Mr punch
  • 1,756
  • 4
  • 16
  • 23
115
votes
4 answers

CQRS: Command Return Values

There seems to be endless confusion about whether commands should or should not have return values. I would like to know if the confusion is simply because the participants have not stated their context or circumstances. The Confusion Here are…
Brent Arias
  • 29,277
  • 40
  • 133
  • 234
103
votes
11 answers

Why are commands and events separately represented?

What is the difference between commands and events in architectures that emphasize events? The only distinction I can see is that commands are usually sourced/invoked by actors outside the system, whereas events seem to be sourced by handlers and…
alphadogg
  • 12,762
  • 9
  • 54
  • 88
82
votes
8 answers

CQRS Event Sourcing: Validate UserName uniqueness

Let's take a simple "Account Registration" example, here is the flow: User visit the website Click the "Register" button and fill out the form, click the "Save" button MVC Controller: Validate UserName uniqueness by reading from…
Mouhong Lin
  • 4,402
  • 4
  • 33
  • 48
77
votes
14 answers

When to use the CQRS design pattern?

My team and I have been discussing using the CQRS (Command Query Responsibility Segregation) design pattern and we are still trying to asses the pros and cons of using it. According to: http://martinfowler.com/bliki/CQRS.html we haven't seen…
Eric
  • 3,632
  • 2
  • 33
  • 28
67
votes
5 answers

What is the difference between a saga, a process manager and a document-based approach?

What I understand is that all three concepts are related to long-running transactions. A process manager is, to my understanding, a finite state machine which simply reacts on events and emits commands. It does not contain any business logic, it…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
64
votes
2 answers

What is the difference between Command + CommandHandler and Service?

I have been reading about using Command objects to represent use cases that our domain exposes, and Command Handler objects to process those commands. For example: RegisterUserCommand RegisterUserCommandHandler But it looks exactly the same as…
Matthieu Napoli
  • 48,448
  • 45
  • 173
  • 261
62
votes
5 answers

What are the disadvantages of using Event sourcing and CQRS?

Event sourcing and CQRS is great because it gets rids developers being stuck with one pre-modelled database which the developer has to work with for the lifetime of the application unless there is a big data migration project. CQRS and ES also has…
user794783
  • 3,619
  • 7
  • 36
  • 58
59
votes
9 answers

CQRS Examples and Screencasts

I'm looking for some in depth end-to-end CQRS examples with a reasonable set of unit tests. Also, if anyone knows of some CQRS screencasts as well it would be extremely handy. I'm already aware of these examples CQRS Info Super Simple CQRS
Tom Dudfield
  • 3,077
  • 2
  • 25
  • 39
57
votes
2 answers

How to get ID in create when applying CQRS?

My take on CQRS is when followed strictly your commands don't return anything (return type void), so my example is really straight forward: How do you retrieve an ID when creating something? For example, when creating a credit card transaction it…
Tomas Jansson
  • 22,767
  • 13
  • 83
  • 137
50
votes
6 answers

CQRS without Event Sourcing - what are the drawbacks?

Besides missing some of the benefits of Event Sourcing, are there any other drawbacks to adapting an existing architecture to CQRS without the Event Sourcing piece? I'm working on large application and the developers should be able to handle…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
50
votes
12 answers

Domain Validation in a CQRS architecture

Danger ... Danger Dr. Smith... Philosophical post ahead The purpose of this post is to determine if placing the validation logic outside of my domain entities (aggregate root actually) is actually granting me more flexibility or it's kamikaze…
Jupaol
  • 21,107
  • 8
  • 68
  • 100
49
votes
6 answers

Real life experience with the Axon Framework

As part of researching CQRS for use with a project, I ran across the Axon Framework, and I was wondering if anyone has any real life experience with it. Just to be clear, I'm asking about the framework, not CQRS as an architectural pattern. My…
mhvelplund
  • 2,099
  • 3
  • 22
  • 38
1
2 3
99 100