Composite keys for aggregate identifier

Hi,

Is there a way to change the aggregate id to use more than one field?

Thanks

Brijesh

Hi Gopal,

Where exactly do you want to use more then one field to create the aggregate identifier?
Axon mainly requires that the aggregate identifier classes you use have a ‘toString()’ method, as it’ll internally store the identifier as a String.
So as long as the composite key you’ve got in mind provides that ‘toString()’ functionality in a form you’re satisfied with, then yes you can use more than one field.
We typically suggest against composite keys for Aggregates though, as a regular UUID should be more than sufficient in most use cases.

Hope this helps.

Cheers,

Steven

We have a case where the database may be shared among multiple clients and typically in such cases we store a tenant-id along with other keys. Aggregate id alone is guaranteed to be unique in our system so that is not been a real problem, a tenant id as an additional column in the event store would help us to filter data/purge etc. I get that it’s probably better for performance to keep a single primary key column for the event store database(write).

Thanks,
Brijesh

Hi Brijesh,

If you require your event store to be queryable with an additional column for such a use case, you could of course implement your own version of the EventStorageEngine which stores a different Domain Event Entity.
So for example if you’re currently using the JpaEventStorageEngine, nothing stops you from extending from it and overriding the createEventEntity() function to use your DomainEventEntry which has the additional tenant id column you require.

Hope this helps!

Cheers,

Steven