title: DDD aggregate design example with a many-to-many relationship
body: <p>I would like to run through a modelling exercise to try and understand DDD a little better, specifically in the cases where there is a many-to-many relationship</p>
  
  <p>Lets take an example of Xbox users and their achievements.</p>
  
  <p>If you are not familiar this is the background:
  Each game on Xbox has achievements.
  User will have a list of games they own/have played and they can unlock achievements for these games.</p>
  
  <p>There is a many-to-many relationship here as a user can have many games, and a game can have many users.</p>
  
  <p>Without going further, there is definitely two aggregate roots here. User and game.
  The game aggregate root has a list of achievements.</p>
  
  <p>My confusion comes in with tracking the progress of a user for a specific game.
  for instance what games they have, and what achievements they have for each game.</p>
  
  <p>In a typical CRUD design it might look something like this:
  <a href="https://i.stack.imgur.com/fTJip.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTJip.png" alt="enter image description here"></a></p>
  
  <p><strong>How would you now model this is DDD?</strong> </p>
  
  <p>User Game and User Achievement will have information regarding the progress of each.</p>
  
  <p>This is a solution i currently think, but is it right?</p>
  
  <p><a href="https://i.stack.imgur.com/6yCqU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6yCqU.png" alt="enter image description here"></a>
  User and game are both aggregate roots.</p>
  
  <p>The progress of a game and it's individual achievements also seems to be connected and I would say that this is its own aggregate root. This is because like game and it's achievements, it potentially has a transaction boundary. When you progress on a game's achievement, this could effect the game's progress (e.g. unlocking an achievement would up the total game's gamerscore achieved.)</p>
  
  <p>I keep hearing that you want to resolve many-to-many relationship, which is usually fine, but here, the relationship has its own data, and I don't think this relationship belongs to either.</p>
  
  <p>You might be able to argue that you would put this on the user aggregate, but my concern is that it adds weight to that user aggregate and there is no reason for it to be there.
  I don't think there is any transaction boundaries and I don't like the though of having to load all the user's games when you want to load it. Even if this was lazy loaded, I am concerned it might cause concurrency issues?</p>
  
  <p>This is why I think the many to many relationship here is valid, and why a new aggregate root might be appropriate. </p>
  
  <p>Also is the name user game progress even correct. Knowing the domain, what might you suggest?</p>
  
  <p>Thank you, any help is massively appriciated.</p>