1
votes

If we use an Order as an Aggregate Root (AR) and OrderLines as non-root Aggregates, how do you handle the case where performance is an issue?

I am using Order/OrderLine as they are a familiar enough part to be in all our "Ubiquitous Language". So please play along that my "Order" is computationally difficult to store and more so to retrieve. When not using DDD, it would be common to "de-normalize" those into a "View". With DDD, might one create an OrderView domain object and use the Order AR to write, and the OrderView AR to read? How have others handled this situation?

Thanks in advance for any advice.

1
Isolating and/or separating the read flow from the create/write flow is actually an option for my needs. However, this seems, to me, orthogonal to the question. That is, the same question exists, though slightly modified. As that separation affords you two models, is the read/query model modeled in the DDD layer? If so, same question. If not, what do you do? Have the "queries" go directly against a "Repository Layer" that then outputs DTOs? - JoeG
Your read/query model should not be part of your domain layer in my opinion. The domain layer is about enforcing invariants on your business entities. Querying data doesn't fit that criteria to me. That is why I generally put this kind of functionality in the application layer. You don't need any repositories for querying, just simple ADO.NET data readers mapped to DTO's is usually enough. No need to get fancy for the read side of your system. - Tyler Day

1 Answers

0
votes

We handle this by creating simple data transfer objects which get populated in an application handler by an underlying SQL view which is comprised of data from our underlying domain entity tables. We've found this works very well and have had no issues. I wouldn't call this CQRS since we are using the same model for both commands and queries, but maybe you could call it CQRS-lite. I would strongly recommend you do not create view objects in your domain layer. It gives you no real value, and only adds a layer of complication.