"Trying to insert an Event for an aggregate with a sequence number that is already present in the Event Store".

We are beginning to see to these errors in our logs:

“Trying to insert an Event for an aggregate with a sequence number that is already present in the Event Store”.

@Allard
If Allard or anyone else have come across these error before, let me know what did you do to resolve it. Anyone?
Thanks.

Hi Joseph,

this is quite common of you have a multi-node setup, where commands are divided between the nodes randomly (or at least inconsistently). I have also seen this error pop up in cases where only a single node runs the application. It had to do with the database’s transaction isolation settings. Setting it to read-committed (or read-uncomitted, if you prefer) resolved that issue.

Some background:
Axon uses locking. Imagine Thread 1 and Thread 2 sending a command that routes to the same aggregate instance. The command bus starts a transaction for both (usually this means a connection is also acquired). Thread 1 loads the aggregate, while Thread 2 blocks at the lock. Thread 1 finishes processing and publishes the results. Thread 2 is released and loads the aggregate. Because the transaction was started before Thread 1 committed, it is possible that the database doesn’t show Thread 1’s results because of the isolation level.

If you use Spring, I also recommend using the LazyConnectionDataSourceProxy, as it will postpone getting the actual connection until it’s really used.

Cheers,

Allard

Thanks Allard. My team and I try the pointers provided.

Have a great day,

Joseph