Axon snapshot

Reading Time: 3 minutes

Aggregate Snapshotting

The ability to take snapshots of your application and data can be crucial in maintaining its performance. That’s why we’re introducing snapshot events – a special kind of domain event that can summarize an arbitrary amount of events into a single one. Snapshot events can help reduce the number of events that need to be loaded in order to rebuild an aggregate’s state, thus reducing the performance impact on applications when axon aggregates live long enough for their state to constantly change. This is just another way we’re innovating in the world of software development, simplifying complex processes and improving the user experience.

Keeping your Event Store from Overflowing: the Power of Snapshot Events We all know that when an Axon Aggregate lives for a long time and its state is constantly changing, it will generate a large number of events. But loading all these events into the application to rebuild the aggregate’s state can have a huge performance impact – which is why snapshot events are so important.

A snapshot event is a special kind of domain event that summarises an arbitrary amount of events into a single one. By regularly creating and storing one of these, you can drastically reduce the amount of information needed to reconstruct an aggregate, therefore greatly improving performance. So if you want to keep your event store running smoothly, don’t forget to use snapshot events.

Keeping track of Axon Aggregates is no small feat. With states that are constantly changing, their event logs can become overwhelming and create a huge performance impact on applications. That’s why we recommend creating and storing snapshot events – domain events with the special purpose to summarise an arbitrary amount of events into a single one. By doing this, you can reduce the load on event stores and prevent them from returning long lists of events. This approach makes life easier for developers and keeps your application running smoothly!

You can see in this application we have set a snapshot configuration. When Bike events cross the 2 thresholds then the snapshot starts and it will be stored in a bike events backup.

@Configuration
public class SnapShortConfig {
@Bean
public SnapshotTriggerDefinition bikeSnapshot(Snapshotter snapshotter) {
    return new EventCountSnapshotTriggerDefinition(snapshotter, 2);
}
}

Commands Initiate

Maximizing productivity and efficiency with the Axon Framework

Do you want to build a modern distributed system capable of processing queries quickly and accurately? If so, then check out the Axon Framework! In this article, we explored three approaches to dispatching queries within the Axon Framework: point-to-point queries, scatter-gather queries, and subscription queries. The complete code examples for this article are available over on GitHub. Get started now and make the most out of your projects! Check it out to get started with Axon Query Dispatching.

Axon Server dashboard

You can check the axon snapshot from the server dashboard when you hit the URL http://localhost:8024 and navigate to the search section and check on snapshots

Launch Axon Server

Make sure before this application starts you would be run the axon server with help of docker-compose.yml

> docker-compose up -d
> docker-compose down

In a summary, Snapshot events can help reduce the number of events that need to be loaded in order to rebuild an aggregate’s state, thus reducing the performance impact on applications when axon aggregates live long enough for their state to constantly change. For live session or demo you can download a sample application from GitHub.

Written by 

Abid Khan is a Lead Consultant at Knoldus Inc., postgraduate (MCA), and having 5+ years of experience in JavaSE, JavaEE, ORM framework, Spring, Spring-boot, RESTful Web Services, Kafka, MQTT, Rabbitmq, Docker, Redis, MySQL, Maven, GIT, etc. He is a well-developed professional with a prolific track record of designing, testing, and monitoring software as well as upgrading the existing programs.