I am new to Event sourcing with CQRS. I am trying to define what will be the aggregate roots of my program. Lets say I have these 2 entities: Car and Person. And one invariant: a car can only be owned by one Person.
It is basically a 1-TO-M association between Person and Car
And I have this three commands:
Repaint a car (Only car id is given)
Change car owner (Car id and new Person id is given)
- Repaint all cars owned by a Person (only person id is given)
If I use Car as an AR, the command #1 is quick to run. I will push a CarRepaint event. Command #2 is also quick to run (push CarIsOwnedBy event) But the problem occurs for command #3, I need to go through all events in the store to get each Car owned by a specific Person. The invariant is also easy to implements.
If I use Person as an AR, the command #3 is quick to run. I will push CarRepaint event for each car associated with the person. But the problem occurs for command #1, #2, I will need to go look at all events in the store to find the good car. I also have problem making sure the invariant stays true.
Am I approching the problem in the wrong way?
Thanks for your help