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

In DDD with CQRS how to initialize aggregate with the list of sub-entities

I'm building a DDD application with CQRS. In my aggregate I have a Budget aggregate root and BudgetedTransaction entity. Budget keeps track of the transactions, the list of BudgetedTransactions is the property of the Budget. In the database that's a…
Karol Skrobot
  • 450
  • 3
  • 19
0
votes
1 answer

How to handle exceptions in event handler in Axon

I am building a monolith project using Axon framework. I have a method here that dispatches an event @CommandHandler public void createRoom(CreateRoomCommand createRoomCommand){ log.info("Receiving create room command:…
fragilepriCe
  • 59
  • 1
  • 4
0
votes
1 answer

J Oliver EventStore/CommonDomain SagaBase

Why is SagaBase generic in Jonathan Oliver's CommonDomain library?
Joe
  • 169
  • 9
0
votes
1 answer

How to use interface as events in CommonDomain and NEventStore?

I'm conducting a test using JOlivers CommonDomain and EventStore with NServiceBus. I need to raise an event in my Aggregate like this: RaiseEvent(bus.CreateInstance(m => { m.Number = number; })); And then later i have this…
Werner
  • 1,229
  • 1
  • 10
  • 24
0
votes
1 answer

How to get state at specific date in an Event Sourcing based system?

In a CQRS/Event Sourcing system you have current state in the Read Model (as projections). But what if I need to get data at specific (older) date? In the Write Model you can replay events until the date you want but you shouldn't query the Write…
Jose Alonso Monge
  • 1,014
  • 1
  • 16
  • 29
0
votes
1 answer

Calling next event in saga - Axon

I have 2 events OrderCreatedEvent and ProductReservedEvent. Saga event handlers are as follows: @StartSaga @SagaEventHandler(associationProperty = "orderId") public void handle(OrderCreatedEvent event){ LOGGER.info("Saga Started…
0
votes
1 answer

DDD, events and projections how to combine them

I'm creating a project using event sourcing and DDD techniques, for fun and learning. Actually I think about projections in my project, where to locate their ports and adapters. At this time, I'm creating user context. I think interfaces/ports for…
0
votes
1 answer

How to record/implement object status in event sourcing?

I'm solving a problem that might seem simple, but in event storming I'm not sure how the implementation should be done. I have an application that works like dropbox, the user get to upload files and on top of those files the user can run a series…
Cesar Flores
  • 762
  • 7
  • 16
0
votes
1 answer

How to keep a view table updated on CQRS/Event Sourcing patterns

What is the best way to keep a view table up to date, using the CQRS/Event Sourcing pattern? The most common way is through KSQL queries, but I would like to know if there is a more generic way, for example, using a relational database. The more…
juanmorschrott
  • 573
  • 5
  • 25
0
votes
2 answers

Modelling aggregates with subtypes (DDD/CQRS)

I have a subdomain which involves tracking user financial data across different financial account types. For example, users can input data for their: bank accounts, credit cards, loans, lines of credit, real estate, and more... Now within each…
Nelav
  • 45
  • 6
0
votes
1 answer

Getting an empty return from a faked repository call

I'm trying to write unit tests for my CQRS classes. I thought I'd start with a very simple query that returns a view model object. I want to write a test such that when I pass in a valid ID, I ensure I get the corresponding object back from the…
Jester1811
  • 23
  • 5
0
votes
1 answer

How to create read and write separate repos in CQRS architecture

I have this interace and repository
Toma Tomov
  • 1,476
  • 19
  • 55
0
votes
1 answer

CQRS Where to Query for business logic/Internal Processes

I'm currently looking at implementing CQRS driven by events (not yet event sourcing) in for a service at work; the reasoning being: I need aggregate data to support a RestAPI coming out of this service (which will be used to populate views)-…
0
votes
1 answer

class path resource [io/axoniq/axonserver/config/MetricsConfiguration.class] cannot be opened because it does not exist

Am trying to create a microservice using spring boot and axon framework to achieve CQRS and Event sourcing. Am getting the FileNotFoundException when I run the Application. I couldn't find any solution on internet. Can someone guide me to the…
sai
  • 21
0
votes
2 answers

Fluent validation divide business validation from auth validaton

I'm using ASP, CQRS + MediatR and fluent validation. I want to implement user role validation, but I don't want to mix it with business logic validation. Do you have any idea how to implement this? I mean a specific validator must be executed for a…
Adam
  • 1
1 2 3
99
100