Command Query Responsibility Segregation design pattern
Questions tagged [cqrs]
297 questions
45
votes
5 answers
How does a REST API fit for a command/action based domain?
In this article the author claims that
Sometimes, it is required to expose an operation in the API that inherently is non RESTful.
and that
If an API has too many actions, then that’s an indication that either it was designed with an RPC…

leifbattermann
- 736
- 1
- 5
- 9
29
votes
2 answers
How exactly should a CQRS Command be validated and transformed to a domain object?
I have been adapting poor-man's CQRS1 for quite some time now because I love its flexibility to have granular data in one data store, providing great possibilities for analysis and thus increasing business value and when needed another for reads…

Andy
- 10,238
- 4
- 25
- 50
29
votes
6 answers
Better to have 2 methods with clear meaning, or just 1 dual use method?
To simplify the interface, is it better to just not have the getBalance() method? Passing 0 to the charge(float c); will give the same result:
public class Client {
private float bal;
float getBalance() { return bal; }
float charge(float…

david.t
- 437
- 4
- 7
25
votes
2 answers
ES / CQRS concurrency handling
I recently started to dive into CQRS / ES because I might need to apply it at work. It seems very promising in our case, as it would solve a lot of problems.
I sketched my rough understanding on how an ES / CQRS app should look like contextualized…

Louis F.
- 353
- 3
- 6
23
votes
3 answers
When using DDD and CRQS, should be exactly one event per command?
I am looking for a way to design a ddd application with convention over configuration.
Say an aggregate "Client" has a command defined "FillProfile". It will logically raise an event "ProfileFilled".
Are there cases when a command will raise more…

Ludovic C
- 603
- 5
- 9
23
votes
2 answers
DDD CQRS - per-query and per-command authorization
Summary
Should authorization in CQRS/DDD be implemented per-command/query or not?
I am developing for the first time an online application using more or less strictly the DDD CQRS pattern. I bumped into some problem, which I can't really get my head…

Ludovic C
- 603
- 5
- 9
21
votes
2 answers
Isn't CQRS overengineering?
I still remember good old days of repositories. But repositories used to grow ugly with time. Then CQRS got mainstream. They were nice, they were a breath of fresh air. But recently I've been asking myself again and again why don't I keep the logic…

SiberianGuy
- 4,753
- 6
- 34
- 46
20
votes
3 answers
How to handle post-validation errors in command (DDD + CQRS)
For example, when you submit a Register form, you have to check in the Domain Model (WriteModel in CQRS) that it is in a valid state (example, email address syntax, age, etc).
Then you create a Command, and send it to a Command Bus.
I understand…

JorgeeFG
- 659
- 4
- 13
20
votes
2 answers
How to implement a process manager in event sourcing
I'm working on a small example application to learn the concepts of CQRS and event sourcing. I have a Basket aggregate and a Product aggregate which should work independently.
Here's some pseudo code to show the implementation
Basket { BasketId;…

Ivan Pintar
- 1,177
- 1
- 8
- 15
20
votes
5 answers
DDD, Saga & Event-sourcing: Can a Compensate Action simply be a delete on the event store?
I realize the above question probably raises a few 'what??'s, but let me try to explain :
I'm trying to wrap my head on a couple of related concepts, basically the Saga-pattern ( http://www.rgoarchitects.com/Files/SOAPatterns/Saga.pdf) in…

Geert-Jan
- 673
- 1
- 5
- 13
18
votes
1 answer
Should I use a command or an event?
The difference between a command and an event in bus communication seems a little vague to me. I know that commands should be executed once only, while an event can be handled multiple times, but still I'm not sure when to use a command or an event.…

Andrzej Gis
- 973
- 9
- 17
17
votes
5 answers
Is it bad practice for services to share a database in SOA?
I have recently been reading Hohpe and Woolf's Enterprise Integration Patterns, some of Thomas Erl's books on SOA and watching various videos and podcasts by Udi Dahan et al. on CQRS and Event Driven systems.
Systems in my place of work suffer from…

Paul T Davies
- 3,144
- 2
- 22
- 22
16
votes
3 answers
In CQRS/ES, can a command create another command?
In CQRS/ES, a command is sent from the client to the server and routed to the appropriate command handler. That command handler loads an aggregate from its repository, and calls some method on it, and saves it back to the repository. Events are…

magnus
- 664
- 1
- 5
- 14
16
votes
2 answers
Why separate class CommandHandler with Handle() instead of handling method in Command itself
I have a part of CQRS pattern implemented using S#arp Architecture like this:
public class MyCommand
{
public CustomerId { get; set; }
// some other fields
}
public class MyCommandHandler : ICommandHandler

rgripper
- 265
- 1
- 2
- 11
16
votes
3 answers
Are Domain Objects in Domain Driven Design only supposed to be write-only?
I've been reading about Domain Driven Design for almost two years and have been cautiously been introducing some concepts in to my daily work or at least making plans for how things I do regularly could be done within a Domain Driven Design.
One…

jpierson
- 301
- 3
- 7