title: How to properly define an aggregate in DDD?
body: <p>What would be a rule of thumb when designing an aggregate in DDD?</p>
  
  <p>According to Martin Fowler, aggregate is a cluster of domain objects that can be treated as a single unit. An aggregate will have one of its component objects be the aggregate root.</p>
  
  <p><a href="https://martinfowler.com/bliki/DDD_Aggregate.html" rel="noreferrer">https://martinfowler.com/bliki/DDD_Aggregate.html</a></p>
  
  <p>After designing aproximatelly 20 DDD projects I am still confused about the rule of thumb when choosing domain objects that would create an aggregate.</p>
  
  <p>Martin Fowler uses order and line-items analogy and I don't think it is a good example, because order+line-items are really tightly bounded objects. Not much to think about in that example.</p>
  
  <p>Lets try with car analogy where CarContent is a subdomain of a car dealer domain. </p>
  
  <p>CarContent would consist of at least one or more aggregate/s.</p>
  
  <p>For example we have this AggregateRoot (i am keeping it as simple as possible)</p>
  
  <pre><code>class CarStructureAggregate
  {
       public int Id {get; private set;}
       public ModelType ModelType {get; private set;}
       public int Year {get; private set;}
       public List&lt;EquipmentType&gt; {get; private set;}
  }
  </code></pre>
  
  <p>Alternative could be this (example B)</p>
  
  <pre><code>class CarStructureAggregate
  {
       public int Id {get; private set;}
       public ModelType ModelType {get; private set;}
       public int Year {get; private set;}
  }
  
  class CarEquipmentAggregate
  {
      public int Id {get; private set;}
      public List&lt;EquipmentType&gt; {get; private set;}
  }
  </code></pre>
  
  <p>Car can be created without equipment but it cannot be activated/published without the equipment (ie. this can be populated over two different transactions)</p>
  
  <p>Equipment can be referenced trough CarStructureAggregate in example A or using CarEquipmentAggregate in example B.</p>
  
  <p>EquipmentType could be an enum, or could be a complex class with many more classes, properties.</p>
  
  <p>What is a rule of thumb when choosing between examples A and B? 
  Now imagine that car could have more information such as</p>
  
  <ul>
  <li>photos</li>
  <li>description</li>
  <li>maybe more data about the engine</li>
  </ul>
  
  <p>and CarStructureAggregate could be an extremely large class</p>
  
  <p>So what is it that makes us split Aggregate into new Aggregates? Size? Atomicity of a transaction (although that would not be an issue since usually aggregates of a same sub domain are usually located on the same server)</p>