What is usually done when an aggregate is asked to apply an "impossible" event to its state?
For example, if a
ShoppingCart aggregate has already applied a
CustomerAckRec (The customer has acknowledged receiving the shipped item) event, and is now asked to apply an
This question confuses me, because on one hand, it makes no sense to apply that event. Adding the item would create an impossible state, but so would just swallowing the event and leaving the state as is.
Seems like an error should be thrown. But this means that a simple application of an event is now a failable action, so we need to handle that failure.
But on the other hand, events are supposed to be the source of truth, so we shouldn't validate them against the current state of the aggregate?
I guess this is philosophically entirely different from the business rule validation of whether a command is successful or not, more of a validation of the data coming from another machine. But in practice, this essentially always duplicates a part of the validation of the command that would have caused the creation of the event! Which is precisely why we assume that this event would never exist in the first place.
So, should I really pretend there isn't any chance that this event will come? Should I just pretend/cast that I know that if this event arrived, the state is such that this event can be meaningfully applied to?
Neither blindly jamming events into the aggregate without any thought about the possible hard to track undefined behavior that would result from corrupted event storage, nor the duplication in validation sits well with me.