Is it possible to create multiple snapshots per aggregateIdentifier?

Good afternoon.

That’s my first experience with Axon and event sourcing, but could you please help me to understand the direction that should be used for some custom logic?

Both EventCountSnapshotTriggerDefinition and AggregateLoadTimeSnapshotTriggerDefinition provides the implementation for snapshot creation. But when the snapshot is created by any of those definitions, an existing snapshot is updated only. Is there any way to store snapshots daily? I’ve been looking for this kind of functioonality, but it looks like a default behaviour. Here I also realize, that might work this way due to CQRS pattern and delegation of snapshot persistence to other components. Is there any way to to this, or I should consider projection usage to be the only alternative?

I would very much appreciate your guidance and comments

Thank you

Welcome aboard @orange256!
Be sure to reach out with any questions you might face here on the forum.
Furthermore, I hope you’ll find your journey into Axon a pleasant one.

Interesting request, @orange256.
Perhaps you can share why you are looking for this functionality?
With that bit of information added to your questions, other readers would be better suited to understand where you (and your team) are coming from, making it clearer whether somebody else’s needs align.

Regardless of that information, I am confident I can help you further.

Firstly, the “overriding” behavior of snapshots only occurs for the RDBMS- and Mongo-based storage solutions. If you would use Axon Server, each snapshot will be a unique entry. If you are inclined to use an RDBMS or Mongo EventStore, that means you have some manual steps to undertake.

The simplest one to adjust would be the JdbcEventStorageEngine as it allows users to adjust any SQL query. In your scenario, you would be required to adjust the appendSnapshot operation to make unique entries instead of overwriting existing ones. To configure different statements, you will be required to build a JdbcEventStorageEngine through it’s builder (the JdbcEventStorageEngine.Builder class, which you can retrieve through JdbcEventStorageEngine#builder).

Secondly, if you want daily snapshots at a fixed point in time, you will need to construct a custom SnapshotTriggerDefinition. The EventCountSnapshotTriggerDefinition and AggregateLoadTimeSnapshotTriggerDefinition work on a total event count and overall load time respectively. When these milestones are hit, a snapshot will be created.

For fixed daily snapshots, you would thus write a SnapshotTriggerDefinition that keeps track of time to ensure a snapshot is created once every day for the active aggregates.

This is, obviously, some custom code. Configuring a custom SnapshotTriggerDefinition is no different from configuring the event-count and load-time-based triggers, though.

Concluding, I hope this helps you further, @orange256!
If not, be sure to reply below. :slight_smile:

1 Like