title: DDD - Aggregate Roots - Dealing with Efficiency and Concurrency
body: <p>First off, I'll admit that I'm a newbie to DDD and need to read the "<a href="https://rads.stackoverflow.com/amzn/click/com/0321125215" rel="nofollow noreferrer" rel="nofollow noreferrer">blue book</a>".</p>
  
  <p>I'm building a system that has an AggregateRoot of type "Match". Each Match can have a collection of "Votes" and also has a readonly "VoteCount" property which gets incremented when a user up-votes or down-votes a Match.</p>
  
  <p>Since many users could be voting on a Match at the same time, Votes have to be added/removed from the Match and the VoteCount has to be incremented/decremented as one atomic operation involving write locks (with locks handled by the DB). (I need VoteCount as a static value in the database to be queried on efficiently by other processes/components.)</p>
  
  <p>It seems to me that if I were adhering to strict DDD, I would be coding this operation as such:</p>
  
  <p>An application service would receive a vote request object
  The service would then retrieve the Match object from a Match Repository
  The service would then call some sort of method on the Match object to add the Vote to the collection and update VoteCount.
  The Repository would then persist that Match instance back to the DB
  However, this approach is not feasible for my application for 2 main reasons, as I see:</p>
  
  <p>I'm using MongoDB on the backend and cannot wrap this read-write operation into a transaction to prevent dirty reads of the Match data and its associated Votes and VoteCount.</p>
  
  <p>It's highly inefficient. I'm pulling back the entire object graph just to add a Vote and increment VoteCount. Although this is more efficient in a document db than in a relational one, I'm still doing an unnecessary read operation.</p>
  
  <p>Issues 1 &amp; 2 are not a problem when sending a single Vote object to the repository and performing one atomic update statement against Mongo.</p>
  
  <p>Could Vote, in this case be considered an "aggregate" and be deserving of its own repository and aggregate status?</p>