AggregateSnapshot and breaking changes of aggregate

Hi Axon users,

How does Axon deal with changes on aggregates when you are having AggregateSnapshot’s?
AggregateSnapshot is storing the entire aggregate so I can imagine unserialize the aggregate when fields is removed or modified.

I have tested upcasters but they doesn’t get called with my AggregateSnapshots.
The ideal solution would probably be for me that we run rebuild the snapshots again from the events.

I couldn’t find anything about this in the official documentation?
I hope anybody can help answering this.

Regards,
Theis

Hello Theis,

Your request is noted. Thanks for sharing!
AxonIQ opened an issue for that: https://github.com/AxonFramework/AxonFramework/issues/1391

Right now, the best option you have is to configure a snapshotFilter on the AxonServerEventStore on your own.
Snapshots for older aggregate types could be ignored this way, instead of attempting to initialize an aggregate based on them.
I do not have some examples for you at the moment.

Best,
Ivan

Example:

Somewhere in the @Configuration:

@Bean
public EventStore eventStore(AxonServerConfiguration axonServerConfiguration,
                             AxonConfiguration configuration,
                             AxonServerConnectionManager axonServerConnectionManager,
                             Serializer snapshotSerializer,
                             @Qualifier("eventSerializer") Serializer eventSerializer) {
    return AxonServerEventStore.builder()
            .messageMonitor(configuration
                    .messageMonitor(AxonServerEventStore.class, "eventStore"))
            .configuration(axonServerConfiguration)
            .platformConnectionManager(axonServerConnectionManager)
            .snapshotSerializer(snapshotSerializer)
            .eventSerializer(eventSerializer)
            .snapshotFilter(this::filterSnapshot)
            .upcasterChain(configuration.upcasterChain())
            .build();
}private boolean filterSnapshot(DomainEventData<?> it) {
    return it.getPayload().getType().getRevision().equals("2.0");
}

On the Aggregate:

@Revision("2.0")
@Aggregate(snapshotTriggerDefinition = "routePlanExecutionSnapshotDefinition")
public class MyAggregate { ...

This will take only the snapshots for version 2.0 only. Other snapshots will be ignored.

Hi Ivan,

Thanks for your reply on this. Sad it isn’t something you support. There must be many with this issue. But your suggestion is better than nothing.

We still have an Axon 2 version of our application that we are forced to maintain (we are working on upgrading). Here does this not seem to be an option.
Do you have any advises against deleting the snapshots? I mean, they ain’t our single-source-of-truth (events is).

I would think that we then automatically re-creates updated snapshots when aggregates its touched next time. Performance can of course then be expected

Hi Theis,

Do you have any advises against deleting the snapshots?

To be honest, I think it’s perfectly fine to drop your snapshots.
However when using Axon Server, the snapshots file does not give you an easy handle to “just remove this type of aggregate snapshots”.
Hence why Ivan is giving the suggestion he just gave; and the issue to simplify filtering of course.

Cheers,
Steven

Thanks Steven,

So far we don’t use Axon Server. But it is a good point that it might make it a bit harder if we migrate to it.

Regards,
Theis