Search code examples
design-patternsdomain-driven-designcqrsdomain-eventscommand-query-separation

How to generate read data in CQRS from existing write database?


Currently we have an Asp.net application which uses SQL server for write and also read queries as a normal monolith application.

Now we want to move to CQRS.

In CQRS the read model is generated on basis of events.

But for the previous transactional data of my application, we do not have any events or logs.

So how can we generate read model in an NoSql database from data of our existing SQL server database.


Solution

  • In CQRS generally does not require to generate Read model from events, CQRS it is approach to split Read from Writes it does has nothing with events. For first step moving to CQRS you can use the same model (same tables from Database) as you use it for now. Only thing you will split the API logic All actions that modifies state of System like Create Update Delete operation should be done by executing commands. and Read just by queries.
    If you really need in your case separate Read model yes you will need to implement in next step Events and EventHandlers that will generate Read model. To be more easier for it you can take a look at AppFactory project CQRS