3

We have a micro-service that has a Domain Model and have an analytical service for the domain which has its own Query Model. The domain model and the query model are stored in separate persistencies.

Currently our Query Model uses a sub-set of the attributes from the Domain model. However going forward we have requirement to add additional attributes from the Domain Model to Query Model, in this case are there any recommendations with regards to the best approach that can be used to populate the 'delta' part of the Query Model with what is available in Domain Model?

As an aside, this also seems to be a weakness of the CQRS any enhancements to the Query Model would require some sort of reload of the data to populate the enhanced part of the Query Model. Or are we doing something wrong here?

1
  • If you separate a read model from the write model, you have to have a mechanism that synchronizes them; events can serve that purpose, hence Event Sourcing is often used with CQRS.
    – Erik Eidt
    Jan 24, 2018 at 14:49

1 Answer 1

1

Assumption: you don't use Event sourcing.

You can use a one-time import script that fetches the needed data from the Write model and populate the Read model. This script stays in the Infrastructure layer and it can be discarded after the re-initialization is done. If you can afford a downtime, you bring down the Read model (stop directing requests to it), migrate the schema and code, run the import script, then bring it up.

If you can't afford a downtime, you must use deploy the new Read model but not use it until the script has finished the import. Then, using some kind of synchronization between the script and the old Read model, the traffic is redirected to the new Read model and you can discard the old Read model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.