Apply events to a wrong aggregate

91 views
Skip to first unread message

José Luis Martinez de la Riva Manzano

unread,
Nov 30, 2016, 12:03:59 PM11/30/16
to DDD/CQRS
When using EventSourcing, we just load all events from EventStore with the AggregateId given in the Command in order to reconstitute the Aggregate to current state.
So if the given AggregateId exists, we load all events of this AggregateId. If using OO then we use the internal apply to bring the Aggregate to current state. If using functional approach, we left fold all events from a init state to current state.

What's happen if the command comes with an AggregateId that doesn't exist for the Aggregate we want to reconstitute, but by chance the AggregateId exists for other Aggregates and then there are events in the EventStore

Should in OO throw NotFound when "internal apply" couldn't apply an event
Should in functional approach throw NotFound when in the left fold an event doesn't have a pattern match?

Greg Young

unread,
Nov 30, 2016, 12:06:48 PM11/30/16
to ddd...@googlegroups.com
Streams don't have to be id based, it could also be customer-{id}
which would make this apparent.

It is quite common that an aggregate/fold does not handle all of the
events in the stream. Even the simplecqrs example has this feature in
it. In simplecqrs note that there is a namechanged event and
checkedin/checkedout none of which it cares about.

Cheers,

Greg
> --
> You received this message because you are subscribed to the Google Groups
> "DDD/CQRS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to dddcqrs+u...@googlegroups.com.
> Visit this group at https://groups.google.com/group/dddcqrs.
> For more options, visit https://groups.google.com/d/optout.



--
Studying for the Turing test

José Luis Martinez de la Riva Manzano

unread,
Nov 30, 2016, 3:33:35 PM11/30/16
to DDD/CQRS
Totally makes sense!

Thanks,
Jose
Reply all
Reply to author
Forward
0 new messages