In a CQRS architecture without an explicit read model, which processor updates the data store?

This question arose from a kind of existential crisis in developing architecture. In essence, it comes down to asking about it - when is a model of a model is on the command line, should the command handler or event handler update the data store?

In particular, I am curious to find out if there is an acceptable way to approach this, and if descent along one route or another can lead to well-known problems.

To develop, we started with a domain model and some repositories for reading and updating the data warehouse through ORM. These repositories request an existing domain model, and we compare the results with the DTO - we did not think about creating a separate reading model at the moment. Architecture evolved to use the CQRS approach, so we now issue commands to create domain objects, and events occur when commands are executed.

At this moment, we now have several rather complex model objects with all kinds of calculations that occur and who (finally) realized that reading would be much faster if we continue these calculations. So far so unexpected.

There is an idea to save these calculations by adding fields to the current data storage tables, thereby making our model of commands more similar to the reading model. Therefore, the view was expressed that we should update the data store in event handlers, because where the template says that the reading model should be changed.

i.e. if we issue CreateItemCommandwhich is processed CreateItemCommandHandler, which causes ItemCreatedEvent, in turn, is processed by some ItemCreatedEventHandler, then CreateItemCommandHandlerit should be reduced to a simple check of the command and the actual modification of the data warehouse should occur inItemCreatedEventHandler

Logic seems reasonable, but it also creates controversial architecture. I thought the CQRS template required a success event from the command handler to indicate that something had really changed in the domain model?

, , , , , ItemCreatedEvent, .

, ?

+4
2

, CQRS, . , , " ".

, "" CQRS "" . - ( ). , ( , , ).

, - . : , ? ?

, , - , . (/), , , , .

, , . -, ( ), , , , ( , ).

+4

" - - . , - , ?"

, . , , , , , , (/), . , , ? , , . , patten. , , ; .

UPDATE

, , , , , , :

, , , , . SOA "" , , , , , , , ' , , , .

, , . , , , .

+3

Source: https://habr.com/ru/post/1526938/


All Articles