Suggestion/discussion: Way to advice which field on the domain event is the aggregate id, to save space.

If we could advice which field is the aggregateId of an event (much like the @TargetAggregateIdentifier on commands) we could skip storing it in the payload and instead use the aggregateIdentifier that already exists on the event when reading it.

It could also be used for sharding the events.


Answering myself: One could simply omit the aggregateId on the event and add a DomainEventMessage parameter to the event handler.

It’s a bit complicated and many times the aggregate id is part of your domain and you’d want it on your event.

Hi Ted,

my main motivation was to separate the things that the framework needs, from whatever an application needs. The framework needs a String representation of the aggregate identifier. While most applications use a UUID-as-a-String, that is not the case for all of them. I have seen many cases where rich identifier classes were used (mainly to be more expressive about the meaning of an ID). It is considered a good practice by many.

The fact that Axon stores is besides the event payload, is purely for indexing reasons. Axon needs to be able to fairly quickly look up the events of a specific aggregate. In a relational database, the (only?) solution is to store that field separately and index it.

My 2 cents.