Replay Events and Deserialisation

Hi there

We have a system is based on event sourcing. In our events we reference enums. After a refactoring we would like to get rid of some enums. When deleting them our system is failing (obviously) as some events can not be deserialised anymore.

My questions:

  • Does Axon provide a hook during the deserialization (when everything is still a string…) where I good map a deleted enum to an existing one before the event is instantiated?
  • Axon provides the possibility to create snapshots of aggregates. Is it possible to get rid of all events in the eventsource which have been created before the snapshot?
  • Is it good practise to prefer Integers, Doubles, Strings etc in Event-Objects. In this case the enums could have been converted to a String in the event which provides more flexibility when changing enums.

Note:

  • We use the built-in xstream for serialisation of events.
  • We use axon 3.3.3

Cheers
Marco

Hi Marco,

What you are hitting here is new versions of events, which are not necessarily compatible with their previous, serialized format.
This is definitely not an uncommon scenario, hence why the reference guide has a topic on versioning events.

What you in short need to do, is:

  1. Specify a revision number on the versioned event.
  2. Build an Event Upcaster which is dedicated to upcasting the given event from the old to the new revision.
  3. Add the Event Upcaster to the UpcasterChain, in order, which you can in turn add to your EventStorageEngine.
    Now, let me also provide an answer to your other questions, starting with the following:

> Axon provides the possibility to create snapshots of aggregates. Is it possible to get rid of all events in the eventsource which have been created before the snapshot?

Your Aggregate State, thus the snapshot, might and very likely will also chance.
It is thus highly recommended to not remove old events for this purpose, ever.

If you feel it suites the need of your application, it’s fine to drop the events though.
You will however lose a lot of the benefits Event Sourcing gives you.

> Is it good practise to prefer Integers, Doubles, Strings etc in Event-Objects. In this case the enums could have been converted to a String in the event which provides more flexibility when changing enums.

Using only primitives in your events will certainly make de-/serialization easier.
Whether it makes your events clearer however is of an entirely different point.

Using as few value objects in the events themselves is something I would in essence strive for, but eliminating enumerations is not on that list if you ask me.
This is however my personal preference, as I think an enumeration is beneficial to use here.

Lastly, I want to point out that we are on the verge of releasing Axon Framework 4.2.
You state to be working on an Axon 3.3.3 release.
Note that is not the latest Axon 3 release either, so at a minimum I would suggest to upgrade to 3.4.3.
Upgrading to 4.x is however of course suggested even more, especially if you want to be able to utilize practical features like splitting and merging tracking tokens for added scalability.

Hope this helps Marco!

Cheers,
Steven

Hi Steven

Thanks for your quick and thorough answer.

Cheers
Marco