As I understand it, CQRS supporters separate reading models from domain models and have a specific reading model for each necessary projection of the domain model.
From the point of use, how the readable model is stored and retrieved should be transparent - you send a request and get the read model without worrying about how this is done.
Many examples and articles use separate tables to store read models and re-generate them by responding to changes to the domain model.
I do not like this approach for the following reasons:
- Not all possible reading models are often needed;
- Changes to requirements may invalidate existing reading models, so they must all be restored;
- If for some reason the model you read contains properties that cannot be stored during generation, but they need to be calculated, you are forced to use stored procedures / functions / views;
- Since the reading models are separated from the domain models, if caching is used at the application level to change the domain model, you need to tell all applications that the old read models should be removed from the cache;
- Sometimes it is impossible and not desirable to completely denormalize the graph of complex objects, so you need to have read models that are consistent for a specific version of the domain entity, that is, they must be generated in one transaction;
- Some domain objects have properties that change frequently, but they must be included in every model read.
, , :
, . , , , , .
, , . CQRS? , CQRS, , - AJAX - CQRS .