I am new to CQRS and DDD, and I wonder what would be the best way to implement the voting mechanism in the domain model.
On the product, the user can raise / lower the level. There are some rules regarding voting, i.e. You can vote only once, either down or up.
Both voices and products will be the combined root. Is this a better approach? He recommended keeping the units small. Adding a vote to the root aggregate of the product will cause overtime to be inflated.
The problem I'm struggling with is to remove the voice when voting is the aggregate root. You need to know how many votes should be removed. In the command handler, it is not possible to get a vote from the repository using productId and userId. The aggregate index is stored in the database as a single Guid.
The command will contain these fields
Some possible solutions that I found are:
- Use deterministic GUID based on userId and productId
- Votes is a list of aggregates for the product.
- Create a voteId and use this to remove the vote.
- Store the aggregate as a string and use a combination of productId and userId
What would be the best approach?
source
share