Note that there are some explanatory texts on larger screens.

plurals
  1. POReconciling DDD, viewmodels, and performance
    primarykey
    data
    text
    <p>I am starting to learn about DDD and am concerned about the performance implications of retrieving entity objects from persistence and then restructuring them in a viewmodel for the UI.</p> <p>Let's say that I have two aggregate roots:</p> <pre><code>Person Orders ------ ------- personId orderId name personId </code></pre> <p>Each aggregate root has its own repository in charge of basic CRUD operations for the entire aggregate. </p> <p>Let's say that the UI requires the following columns:</p> <pre><code>viewmodel --------- personName numberOfOrders </code></pre> <p>I can think of two ways that I can populate this viewmodel:</p> <ol> <li>Eagerly load all person entities, eagerly load all orders based on personId, restructure loaded entities into the viewmodel.</li> <li>create a JOIN/COUNT(orderId) stored procedure and have the database return data in the same structure as the viewmodel.</li> </ol> <p>Obviously, option 1 can be quite the expensive operation, as there can be multiple persons and multiple orders resulting in MULTIPLE database calls. Option 2 will require only one database call.</p> <p>If Option 2 is the preferred (performant) option, where do I store this "viewmodel" and the so called "database call?" Is there a separate "data service layer" on top of the repositories that I can implement? Or is that an anti-pattern in regards to how DDD is generally implemented?</p> <p>Basically, how do I reconcile complex DDD aggregates with custom UI Viewmodels keeping performance in mind?</p> <h2>UPDATES</h2> <p><strong>Specifications / Query Object</strong></p> <p>In talks with a friend, he had suggested that a possible solution is some sort of specification/query object pattern. The only problem is that we will have to implement this on the repository-level, requiring me to combine the Persons and Orders into one large aggregate. This is something I generally avoid for transaction consistency reasons.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload