AnswerBun.com

Is it a good idea to implement CQRS Read model as an Aggregate?

Stack Overflow Asked by DmitriBodiu on December 13, 2020

Is it a good idea to implement CQRS Read model as an Aggregate? Or the read model should be kept as a POCO class?

2 Answers

Is it a good idea to implement CQRS Read model as an Aggregate?

Not really?

An AGGREGATE is a cluster of associated objects that we treat as a unit for the purposes of data change.

Since queries don't change the data, an aggregate is unnecessary ceremony. Putting a bunch of business data into an object just to take the data back out again doesn't make a lot of sense. Using a POCO/POJO/plain data structure gets the job done.

Answered by VoiceOfUnreason on December 13, 2020

In general when using CQRS you also use an event sourced design, so you don't have DDD entities (and by extension aggregates - at all). Usually when using CQRS, you usually have a "command model" & a "query/read model" where the "command model" is some event queue that you may "snapshot" every X amount of time; and your query model(s) are just use case optimized search data stores where you aren't really interested in modelling a whole aggregate.

Now, even if you aren't using an event sourced system, and you are using DDD with just several "query/read models", chances are you want to create a DDD model and have aggregates on the "command model" and not the "read model", as your "command model" represents your domain view & understanding of your domain reflecting your (DDD) ubiquitous language. The read/query model(s) are more oriented towards fine tuning performance for particular use cases (fast searches in a product catalog for example); or for enriching/aggregating data with other "external-bounded context" information.

As a side note, it is important to note that even though your query/read model is not intended to match 1:1 your aggregate, there is usually some correlation between your command aggregate, and your model DTO.

Answered by tony _008 on December 13, 2020

Add your own answers!

Related Questions

String concatenation attempt causing unexpected error

4  Asked on December 4, 2021 by q-q

 

Merging DataFrames with “uneven” data

3  Asked on December 4, 2021 by ribit8950

   

Printing only the value of a key in a dictionary

3  Asked on December 3, 2021 by mr-mac

 

Javascript – Removing last 3 words from a string

4  Asked on December 3, 2021 by maimok

   

Pandas – handle inf and NaN in one line

2  Asked on December 3, 2021 by 8-bit-borges

   

Javascript onclick action not working on image or icon

1  Asked on December 3, 2021 by carrey

   

What does $p[‘t] mean in this keylogger code?

0  Asked on December 3, 2021 by rickyk95

         

Modelsim signal declaration issue

1  Asked on December 3, 2021 by norick

     

sort object properties and JSON.stringify

24  Asked on December 3, 2021 by innovine

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP