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
13
votes
3 answers

How to query in a Event Driven Microservice architecture?

Let suppose the following simple UC based on a CQRS architecture: We have a backend managing a Business Object, let says a Movie. This backend is composed of 2 Microservices: a CommandManager (Create/Update/Delete Movie) and a QueryManager (Query…
Nico
  • 171
  • 1
  • 7
13
votes
2 answers

How to manage read requests in an event sourced application

I was asked to do some exploration in event sourcing. my objective is to create a tiny API layer that satisfies all the traditional CRUD operation. I am now using a package called 'sourced' and trying to play around with it (Using Nodejs). However,…
nick
  • 460
  • 4
  • 24
13
votes
4 answers

How does process manager keep track of the association between aggregates

Does a process manager make use of correlation-ids or aggregate-specific identifies to keep track of the process it is managing? To put it more clearly with an example, consider Figure 2 on Saga on Sagas: First of all, Process Manager sending a…
Andriy Drozdyuk
  • 58,435
  • 50
  • 171
  • 272
13
votes
3 answers

Event sourcing incremental int id

I looked at a lot of event sourcing tutorials and all are using simple demos to focus on the tutorials topic (Event sourcing) That's fine until you hit in a real work application something that is not covered in one of these tutorials :) I hit…
SharpNoiZy
  • 1,099
  • 2
  • 11
  • 22
13
votes
1 answer

CQRS and Domain Events

CQRS has got me into thinking mode.. I am tryinng to start a new project with CQRS ideas. The main things that I like is 1) the separation of Query and Command. Our Domain queries have been a problem. 2) Using Event Storage for Audit - I wont be…
TheMar
  • 1,934
  • 2
  • 30
  • 51
13
votes
2 answers

Autofac resolve dependency in CQRS CommandDispatcher

I'm trying to implement a simple CQRS-application example. This is a structure of my "Command" part: public interface ICommand { } //base interface for command handlers interface ICommandHandler where TCommand: ICommand { void…
Artyom Pranovich
  • 6,814
  • 8
  • 41
  • 60
13
votes
4 answers

Structure of a CQRS event store

I'm currently trying to understand how to build the internal structure of an event store. What I got so far: An event store has two tables (collections, ...), one for aggregates and one for events. The aggregates table contains the following data:…
Golo Roden
  • 140,679
  • 96
  • 298
  • 425
13
votes
2 answers

Event Sourcing command or event from external system?

In most cases I understand the distinction between a command and an event in a CQRS + ES system. However, there is one situation that I can't figure out. Suppose I am building a personal finance tracking system, where a user can enter…
Akash
  • 2,311
  • 1
  • 20
  • 37
12
votes
1 answer

Event Sourcing vs Event Driven Architecture difference

I was looking in to event base architecture and came to know about two architecture Event Sourcing & Event Driven Architecture. My understanding is following Event driven : used for distributed transactions like saga event is pushed to message…
mubir
  • 719
  • 1
  • 8
  • 15
12
votes
1 answer

Is CQRS a good approach for implementing a social application on Google App Engine?

It seems to me that the CQRS (Command and Query Responsibility Segregation) approach might be suitable for implementing a robust and responsive social application server on GAE, because: CQRS doesn't require a SQL database (which GAE doesn't…
Francis Norton
  • 674
  • 1
  • 8
  • 16
12
votes
7 answers

Domain Driven Design, Domain objects, attitude about Setters

Been watching some Greg Young videos lately and I'm trying to understand why there is a negative attitude towards Setters on Domain objects. I thought Domain objects were supposed to be "heavy" with logic in DDD. Are there any good examples online…
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
12
votes
2 answers

Should Aggregates be Event Handlers

I am currently beginning my first real attempt at a DDD/CQRS/ES system after studying a lot of material and examples. 1) I have seen event sourcing examples where the Aggregates are Event Handlers and their Handle method for each event is what…
Mark Kennedy
  • 421
  • 5
  • 9
12
votes
3 answers

CQRS - how to handle new report tables (or: how to import ALL history from the event store)

I've studied some CQRS sample implementations (Java / .Net) which use event sourcing as the event store and a simple (No)SQL stores as the 'report store'. Looks all good, but I seem to be missing something in all sample implementations. How to…
Remco Ros
  • 1,467
  • 15
  • 31
12
votes
1 answer

Relational database schema for event sourcing

I am trying to store domain events in a postgres database. I am not sure in many things, and I don't want to redesign this structure later, so I am seeking for guidance from people who have experience with event sourcing. I have currently the…
inf3rno
  • 24,976
  • 11
  • 115
  • 197
12
votes
2 answers

EasyNetQ fails to publish to RabbitMQ - PersistentChannel timed out

I am trying to connect to RabbitMQ with EasyNetQ. RabbitMQ is on remote VM. _rabbitBus = RabbitHutch.CreateBus( string.Format("host={0};virtualhost={1}", _hostSettings.Host, _hostSettings.VHost), x => x.Register(l =>…
wojciech_rak
  • 2,276
  • 2
  • 21
  • 30