Snapshotting

Snapshotting is an optimization where the AggregateRoot’s state is saved in the event stream. With snapshotting the state of an aggregate can be restored from a snapshot rather than by replaying all of its events.
In general there is no need for snapshotting when you have less than 100 Events in an AggregateRoot. By default snapshotting is turned off in Sequent.

Sequent supports snapshots on aggregates that call enable_snapshots with a default threshold

You then also need to update the existing StreamRecord’s in the database to ensure they are also eligible for snapshotting.
This can be done via bundle exec rake sequent:snapshotting:set_snapshot_threshold[Usernames,100].

After this snapshots can be taken with the SnapshotCommand. For example by a Rake task.

Important: When you enable snapshotting you must delete all snapshots after each deploy. The AggregateRoot root state is dumped in the database. If in the new version the class definition of the AggregateRoots is changed the snapshotted state can not be loaded.

To delete all snapshots do you can execute bundle exec rake sequent:snapshotting::delete_all.