Set base consistency validation using unique field on event?

So I just found the problem on my project which is related to set base consistency validation. I have read the suggested solution on the axon blog, but It requires some additional memory for the lookup table. I wonder if this is possible since AxonServer stores every events anyway can I just make the email field on event become unique(maybe using annotation like mongodb does have) and if the new event comes with duplicate email it could not save this event to EventStore and throws the error on Aggregate. I expect something like this.

data class AccountCreatedEvent(
  val firstName: String,
  val lastName: String,
  @Unique
  val email: String
)

So it will change database schema for the event store become like this.

event_id      email(unique)     firstname     lastname
2             jonh@mail         john          john
1             jane@mail         jane          jane

But I don’t even know how AxonServer stores events and if this is possible to do.

I wonder if this is possible since AxonServer stores every events anyway can I just make the email field on event become unique …

AFAIK that’s not something Axon Server (nor Axon Framework) provides OOTB. You are right though. It would be nice to have such a feature. But there are some design challenges with that.

The first question is, does it really belong to Axon Server? If it were to be on the server-side, applications using other event storage solutions would not benefit. That means using something like @Unique annotations would not be feasible. Those are processed on the Axon Framework side, and they should not depend on a functionality that is only available in Axon Server. Furthermore, migration from one storage to another would result in unexpected functional changes in such a case.

So I personally see 2 ways to implement generic set-based validation (which I think is what you are ultimately asking for):

  1. Axon Server plug-in - one needs to install it manually and be aware of the consequences. The configuration (which fields are unique) should be done on the server-side (via UI / API / …).

  2. Axon Framework extension - Implementing it shouldn’t be too complex. It could automatically do what the blog describes for a (combination of) field(s). That would require configuring storage for the look-up table, though. Thus it’ll still require “some additional memory,” which is your initial concern.

I think both of those can be implemented by the community. If anyone is up to such a challenge, please get in touch. It’s actually quite likely that someone has already implemented something very close to the second option.