Search code examples
domain-driven-designcqrsevent-storming

Event Storming Events?


I have a question in Event Storming or DDD about whether shall all commands trigger an aggregate and then an event or it is not mandatory for each command must have an aggregate with it?

for example:

  • create order (command)-> at least one item in basket(aggregate)->order added (event)
  • create order (command)->order added (event)

Can we have the second example or all commands must go to an aggregate as the first example? I know it might depend on context but is it mandatory or not?


Solution

  • You first need to understand that the events are raised by aggregate. They are the result of modifications (change in state) of aggregate and so do not have a direct impact from command.

    Getting this out, think of events as a change in aggregate. Commands trigger the possibility of change. But if change doesn't occur, then there is no event.

    Consider your example,

    create order (command)-> at least one item in basket(aggregate)->order added (event)

    I'll rewrite it as this:

    Create Order (command) -> Create Order Service (domain) :  
        When (at least one item in basket) (invariant)  
        Then return Order (Order with Order Created Event raised within aggregate)
    

    In the above case, when the invariant fails (no item in basket), then the Order is not created resulting in no event.