I have a checklist system where we are implementing CQRS/ ES (Event Sourcing). We have a command
updateStatus(taskId: string, status: boolean)
to mark a task or sub task as completed. If I receive a command that a sub task is completed, and all the sibling sub tasks are also completed, I have to mark the parent task as completed as well. So in the example below (subtasks 1-3 of task A):
- [ ] task A - open
- [ ] task 1 - open
- [*] task 2 - completed
- [*] task 3 - completed
Tasks A and 1 are both open initially and then I receive a command
updateStatus(task1, completed)
the CommandHandler needs to generate an event taskCompleted(task1).
My question is what is the correct CQRS/ ES requirement:
- Generate a single event: taskCompleted(task1)
- Generate two events: taskCompleted(task1), taskCompleted(taskA)
In the first option I would expect the consumers of events to see that the aggregate should also update itself to be completed. In the second, the command handle takes care of it.
The major downside of option 1 is more processing for command handlers and their deeper knowledge of the aggregate. Another disadvantage is re-use of the events (e.g. say we have logic for sending an email to task owner when it is completed, with option 2 there would simply be a second event handler which just listens to events and acts on them without knowing the full logic).
The major downside of option 2 is a much larger number of events.
Any suggestions on which is the more correct approach using CQRS/ ES?