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
0
votes
1 answer

How to approach a Query that changes the systems state in CQRS?

Consider a situation in a CQRS system where a query would change the system's state. For instance, a cache update, a background job, or some other sync or async task. My question is how to handle this situation. One might say that if you ever faced…
0
votes
2 answers

How to avoid commands calling commands using CQRS in NestJs

I have a use case with two modules : Users Projects I’m stuck with this use case : At register, I have to check if Users mail is already associated to a user. If not, create the user and then create a Projects using the created user id. I have a…
Alexy
  • 780
  • 6
  • 22
0
votes
2 answers

In CQRS with multiple databases, should I call database functions inside Command or inside repositories?

I'm using cqrs pattern with multiples databases (one for query and another for search). Should I put the insert inside Repository CommunityRepository{ Add(Community community){ Database1.Insert(community); …
0
votes
2 answers

is it a good practice to use FluentValidation to validate information within the database?

I'm studying CQRS and FluentValidations and I found myself wondering where would be the best place to validate information within the database: directly in the handlers responsible for orchestrating the requests or within the validations even before…
0
votes
2 answers

NES (.NET Event Sourcing) running older NSB alright?

We have an older installation running with NSB 2.0. I know NES is released for 2.5 but since it's just a layer on top I figure it should be possible to try NES with NSB 2.0. Also, for various reasons the customer does not want to upgrade NSB until…
Werner
  • 1,229
  • 1
  • 10
  • 24
0
votes
0 answers

How to fix error with java.reflect and bean creation in spring boot java

I'll first give some context before showing the error. I am developing a Rest API with Spring Boot (spring boot 2.6.6 and Java 17), in which I started getting the following error when trying to run (with IntelliJ). The complete error queue. Error…
0
votes
1 answer

How should I handle multiple sagas with the same correlation id using J Oliver's CommonDomain library?

I'm using Jonathan Oliver's CommonDomain library for my sagas. The SagaBase class has an Id property which is used as both the correlation id and a unique id for persistence. It doesn't look like it's possible to have multiple unrelated sagas share…
Joe
  • 169
  • 9
0
votes
1 answer

Query subscription with Axon

I work with CQRS and Event Sourcing to project my entity in multiple steps, so every time I send a command to project an attribute After the last command, I want to display all the details of my entity using an API (getMyEntityById). The problem is…
0
votes
2 answers

CQRS - How can a projector replay events?

The thing I can't get my head around is this: The CQRS model tells me that the write and read models are independent of each other. The aggregate only writes to an events table, and publishes events to notify projectors. The projector only consumes…
user1102018
  • 4,369
  • 6
  • 26
  • 33
0
votes
1 answer

.NET DbContext or DbContextFactory

i use clean architecture - https://github.com/jasontaylordev/CleanArchitecture. And im stuck on one problem. I would like use DbContextFactory. But it's problem here. Because DbContext interface - IApplicationDbContext is declared in project…
pietro
  • 143
  • 1
  • 9
0
votes
1 answer

Using MediarR for projects that has no database?

I am a new at MediatR user of .net core platform. And I read that is a nice solution to implement CQRS pattern. So my project does not use any database. And it dows only query from Elasticsearch. So Can I use MediatR in this project and is it make…
barteloma
  • 6,403
  • 14
  • 79
  • 173
0
votes
1 answer

Event Storming Events?

I have a question in Event Storming or DDD about whether shall all commands trigger an aggregate and then an event or it is not mandatory for each command must have an aggregate with it? for example: create order (command)-> at least one item in…
Alireza Rahmani Khalili
  • 2,727
  • 2
  • 32
  • 33
0
votes
2 answers

How can Kafka Streams be used for Event sourcing?

I read about how event sourcing can be achieved by using Apache Kafka as the event broker. (Link to the confluent article) If we take a look at this picture, it shows how event is written into Kafka, and then Kafka Streams is used to create views in…
0
votes
1 answer

CQRS Read Model syncronization: right way to "query" the write models between microservices

I'm trying to follow the database per read/write per microservice pattner with HTTP CQRS API. following this example Asset Microservice Write Model: AssetWriteDb (mssql) Asset class/table public class Asset { public Guid AssetId {get;set;} …
pfab.io
  • 273
  • 1
  • 2
  • 11
0
votes
1 answer

How to add metadata in Event entity of Eventflow

I am working on a web solution that uses .NET 6 framework as backend with EventFlow (Event-sourcing & CQRS). All of my events are store in the table EventEntity : I would like to add additional information in the Metadata attribute. I read the…
1 2 3
99
100