35
votes
Accepted
Should CQRS Command perform a Query?
Let's start with a short review of the problem-space here. The fundamental benefit of adopting a CQRS pattern is to solve/simplify your problem domain by reducing the interleaving and leakage that ...
18
votes
Accepted
Are CQRS and Hexagonal Architecture incompatible?
This is like asking if you can use utensils to eat ice cream. (Yes you can. I recommend a spoon.)
CQRS asks you not to mix together the complexity needed to perform queries with the complexity needed ...
16
votes
Rehydrating Aggregates from a "snapshots" projection rather than the Event Store
What I'm not super clear on is why you would ever rehydrate your Aggregates from the Event Store itself.
Because the "events" are the book of record.
If projecting changes to "read" databases is so ...
14
votes
Accepted
Can CQRS pattern exist without mediator pattern?
Command Query Responsibility Separation (CQRS) separates reading and writing into two different models.
A "conventional" architecture looks like this:
A CQRS architecture looks like this:
Notice ...
12
votes
Accepted
Data Repository and Complex Queries (DTO)
To cut a long story short, this is mostly a matter of self-imposing a design and then trying to make something fit. Something which is very much needed, but doesn't quite fit with the design we ...
12
votes
how can CQRS improve performence when we have to duplicate the writes
The premise of the question is incorrect. Command-Query Responsibility Segregation never required two separate databases; it was about Separation of Concerns between logic that reads data from the ...
11
votes
Zero argument constructors and Always Valid entities
Before I address the kinds of considerations that go into object creation, let's first address the motivation behind your question: the phrase "Always Valid Domain Entities". This phrase is, at best, ...
11
votes
Accepted
CQRS and GraphQL
Software engineering is always a series of trade-offs. You have to give up something to get something else. The unfortunate reality is that we don't always have a full picture of what the impacts ...
10
votes
How exactly should a CQRS Command be validated and transformed to a domain object?
One fundamental premise of DDD is that domain models validate themselves. This is a critical concept because it elevates your domain as the responsible party for making sure your business rules are ...
9
votes
Accepted
Why "Event sourcing an entire system is a big mistake and considered an anti-pattern"?
Event Sourcing is hard and doesn't achieve a great deal on its own.
Also, People confuse Event Sourcing with a whole tonne of other things and find that they haven't achieved what they expected at ...
9
votes
Accepted
CQRS-Event Sourcing: how to process events in the expected order inside the read model
The infrastructure for the event sourcing is an event store which saves the events as documents inside a MongoDB collection and then publish a corresponding message to a service bus, so that with a ...
9
votes
DTO vs. read model
If I understand the concept of read models correctly, then it's just a simple query to return a use case specific data set.
That's not quite right.
DTO's are a boundary artifact
an object that ...
9
votes
Accepted
CQRS command that needs to work with multiple aggregate roots
A comment from Eric Evans DDD Book:
On the other hand, a feature that can transfer funds from one account
to another is a domain SERVICE because it embeds significant business
rules (crediting ...
8
votes
DDD, CQRS, ES - is it worth it or it just waste of time?
Don't do it... its a flawed design policy. Even Greg Young questions its use - but yet peddles his conferences spreading confusion and chaos in systems. There are some specific use cases where ...
8
votes
Accepted
CQRS and microservices: passing information from one service to another
We're building two microservices that use CQRS and Event Sourcing: an Order Service and an Inventory Service. When an order is made, the inventory of that item must be decreased by the amount ordered. ...
8
votes
Accepted
CQRS, How to query aggregate root using others fields rather than GUID (ID)?
CQRS/ES is a tricky architecture in many aspects and you've found one of them.
First of all, since you're storing events it is very hard to query an entity based on its data since you don't actually ...
8
votes
Accepted
how can CQRS improve performence when we have to duplicate the writes
So, how does this actually make reading faster if we still end up writing to it?
It is slower, in the sense that more wall clock time passes from the moment that information is changed in the book of ...
7
votes
Accepted
CQRS - What is the Command Dispatcher?
The Command Dispatcher is not specifically part of CQRS; it's just an implementation detail of the Command Pattern, and an optional one at that.
A Command Dispatcher is an object that links the ...
7
votes
Accepted
Handling aggregate root with deep object hierarchy
If you want to do it the right way as DDD suggests, then you are only allowed to change shape colour by using a method on the aggregate root directly and you cannot do it on the shape directly. The ...
7
votes
Accepted
CQRS+Event Sourcing as Top Level Architecture: Anti-Pattern
The reason ES is generally not a good idea for top-level architecture ("anti-pattern" has no real meaning anymore) is because it's complicated. Plain and simple.
An ES system is going to be more ...
7
votes
In what layer are the DTOs stored with CQRS?
Commands return Domain Models, and Queries return DTOs.
Actually, commands should produce side effects and ideally return nothing (which in some cases isn't practical). Queries should have no side ...
7
votes
Accepted
Clean architecture, CQRS, and authentication?
Looks to me like your issue is:
I have a thread acting on behalf of a user. I don't wish to pollute my nice clean business logic with authorisation details. But my data store needs authorisation ...
7
votes
Accepted
Reducing the code duplication between read and write application in CQRS
It's pretty natural to have some duplication between the Command side and Query side, starting with knowing the same essential Events and payload structures. While standard structures might still be ...
7
votes
Accepted
Event Sourcing - Multiple events or a single for a change on one aggregate?
Short answer: You should generate two events.
A single command invocation can lead to multiple events, so generating more of them really isn't an issue. But why exactly would you want to do that in ...
6
votes
Rehydrating Aggregates from a "snapshots" projection rather than the Event Store
Since you don't specify what would the purpose of the "write" database would be, I will assume here that what you mean is this: when registering a new update to an aggregate, instead of rebuilding the ...
6
votes
How to deal with UI data requirements in DDD
Your Query/View models are being created for data purpose; They are not part of your domain. You typically use Domain modeling for writes, not reads.
You don’t need DDD to read data. But you do need ...
6
votes
What are the problems with command handlers returning data in CQRS?
CQRS is a principle, not a dogma. Like all principles, it has its positive and negative aspects in its own right. Departing from "pure CQRS" could just mean that you can't meaningfully ...
6
votes
Moving shared CQRS/Mediatr Request Handler logic into services and avoiding code/logic duplicity?
For context, I'm working in a similar architecture to yours, and recently I spent a few days investigating how to implement reusable logic that gets reused across commands - so I think we're looking ...
6
votes
Accepted
What should we do in face of a failing sub in pub-sub?
Having 5 subscribers for one event seems only appropriate if all 5 actions are independent, in that the failure of any one doesn't affect the others.
If the failure of one, A, affects another, B, then ...
6
votes
how can CQRS improve performence when we have to duplicate the writes
CQRS Is about more than optimizing reads and writes. It’s also about separating the instructions sent into two different groups. State changing commands, and state preserving queries. Yes doing this ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
cqrs × 310domain-driven-design × 158
event-sourcing × 124
architecture × 44
c# × 31
microservices × 26
design-patterns × 25
read-model × 20
design × 16
aggregate × 15
eventual-consistency × 14
architectural-patterns × 12
domain-model × 10
validation × 10
rest × 9
.net × 9
messaging × 8
event-programming × 7
asp.net-core × 6
repository-pattern × 6
database × 5
object-oriented-design × 5
clean-architecture × 5
dto × 5
command-message × 5