What do you do when validation rules change?

Hi Allard,

For simplicity I’ll assume that I have an aggregate "Customer" that has an attribute “username”. Initially the requirement stated that a username max length is 100 characters. Few months into production the requirements change to max length of 50 characters.

Now my events will fail when an old aggregate is loaded from the event store since the validation rules has changed.

How should one deal with this situation?

I don’t know the axon answer to this, but I can provide the CQRS answer. Hopefully the axon answer is the same.

You validate commands. Command is something someone is trying to do right now. You might accept it, or you might refuse it.

Events already happened. There is no such thing as validating an event, just like you can’t look at a history book and declare that chapter 17, line 10 does not match your validation rules. It is stuff that already happened. You respond to it as best you can, but the time to validate it has passed.

It seems that you DO know the Axon answer. Validation is done on commands, not on events.
In practice, that means that your @CommandHandler annotated methods will have “if” statements (or assertions). Your @Event(Sourcing)Handlers will just do the state changes, without any validation.