Recreate snapshots for all aggregates of a specific type

Hi All!

First as a bit of context, we have an aggregate which has a string attribute with an id. We need to convert the aggregate to hold a list of ids.
One consideration is that we have a couple hundred of these aggregates, but some have millions of events (the largest one has 8m events). We were wondering with my team about what options we have and we came up with these two.

  • Delete the snapshots and re-create the current state, which will potentially pause the application until it completes.
  • Do an ‘expand/contract’ cycle where we add the list and logic to handle both. This logic would null the original field (which should remove it from the snapshot). Also add a command handler that forces the creation of a new snapshot and fire the command on all aggregates. After this is done, remove the old field and command handler.

Do the approaches above sound reasonable? Is there a 3rd approach? I’m tempted to do the 2nd one, but some of my colleagues feel that replaying the whole history is the way to go.

Firstly, sorry for the late reply here @augusto. I hope my 2 cents doesn’t come too late.

Concerning your suggestions, I would recommend taking option one.
Building in separate logic inside your aggregate deviates from the business logic your Aggregate should be about. So, basing yourself on Axon’s approach to constructing snapshots will keep your model clean.

There is, indeed, a third option. If you use the @Revision annotation on your Aggregate, you effectively tell the framework a new aggregate snapshot version. Axon (as of 4.5) will automatically construct a SnapshotFilter based on the @Revision annotation, ensuring you that old snapshots are not used for reconstructing the state.

The problem with both is that you indeed will have “a pause” in your application. Having the means to warm up snapshots (as part of a blue-green deployment, for example) would be ideal. However, there is an issue outstanding to work no such a service actually. You can find it here.

Thanks for the reply Steven!

Unfortunately we are using Axon 4.3 at the moment, but I’ll keep this in mind for when we upgrade.

Hi @augusto,

The annotation @Steven_van_Beelen mentioned is only a ‘shortcut’ for filtering snapshots.
You can still achieve the same creating a SnapshotFilter bean yourself.

Something like this will filter Snapshots that are not of version 1.0.

@Bean
public SnapshotFilter yourSnapshotFilter() {
    return domainEventData -> "1.0".equals(domainEventData.getPayload().getType().getRevision());
}

KR,