Is it a good practice in CQRS to use multiple queryhandlers and/or commandhandlers in each other? Or should you only have one per use-case?
CQRS is an architectural pattern of applying the Single Responsibility Principle which separates the querying from command processing by providing two models(read and write models) instead of one. Thus, it will be a wrong use of the pattern if you use multiple queryhandlers and/or commandhandlers in each other.
This pattern can enable you to scale if you have a very high number of reads. Thus, it is also not an architectural pattern to apply in all bounded contexts of a system.
No, I don't think so.
It's a bad practice, because such way ignores two main advantages of CQRS. First is simple code support and clear structure, because you have separated business logic and queries (aggregated data for visualization).
Second advantage is in scaling. One instance handles commands, and another 5 processes requests. So in theory command code and queries can be executed on different servers. Similarly different queries may be executed on different servers, so including code of commands and queries to each other is bad idea - scaling will be a great pain.
Some CQRS libraries event segregate C & Q sides in different packages, for example here.
Bad idea. If the handler has to do many things such call different databases, 3rd parties, external files, etc Then it SHOULD delegate this to others such repositories, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With