0

As an exercise to building websites and putting DDD to practice, I am currently in the planning stages of creating a crowd voting app based on a video game I play often. The video game allows people to build bases of which can then be attacked by other players. In the app, I want users to be able to either vote up or vote down a base. Voting a base up will increase its score while voting a base down will decrease its score.

I have identified both Users and Bases as aggregates to my domain, where bases will hold a score value based on how many users have voted the base up and down. When a base aggregate is voted up by a user aggregate, the base aggregate will check if the user aggregate has already voted that base up. The following will happen:

  • If the user aggregate has voted the base up, the base aggregate's score will remain the same.
  • If the user aggregate has not voted on the base aggregate yet, the base aggregate's score will be incremented by one.
  • If the user aggregate has voted down the base aggregate, the base aggregate's score will be incremented by two.

The opposite will occur when a user votes a base down. Thus the invariant will hold such that a bases score = (user up votes - user down votes) of which the base aggregate will be responsible upholding. This implies that the base aggregate will be responsible for keeping track of which users have voted on it.

I also want to implement a feature where a user can view all bases they have voted up. This would imply that the user aggregate would be responsible for keeping track of which bases they have voted on.

Which domain aggregate should keep responsibility of maintaining which user has voted on which base? Should I create a new voting aggregate that would maintain these responsibilities?

0

Which domain aggregate should keep responsibility of maintaining which user has voted on which base? Should I create a new voting aggregate that would maintain these responsibilities?

Well, in the real world people vote by submitting ballots, so maybe the ballot is an important concept in your domain as well?

If you dig a bit, you may find additional properties that confirm that ballot is an important entity. For instance, if you are tracking when ballots are cast, that is clearly a property of the ballot, not any particular player or base.

The boundaries of the aggregates primarily depend on how tightly coupled you think the changes in votes are the changes in scores or lists of bases. How important is it that the voter sees that the scores change when his cast (probably not very, if there are other people voting as well). How important is it that the voter sees the new base show up in his list after voting? Maybe some, from a feedback point of view?

Based on what you've written here, most guidance would suggest a fine grain aggregate, so make the ballot the aggregate root and allow the changes to the user's base list and the base score happen independently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.