20 August 2014

What is a Snapshot and when is it useful?

Snapshots are performance optimization and can often be ignored altogether except in the systems where latency is mission critical. Snapshots are a materialization of the stream at a certain revision. The snapshot can then be consumed by an aggregate to bring it back to a known state before applying all events which have occurred since the snapshot. Snapshots, if required, should be handled either by an outside process or, on a minimum, a different thread to avoid blocking main message processing
NEventStore wiki

This is a training project, so I want to see the very basics for implementing some snapshooting policies. That’s what I’ve done in 5 moves:

  1. Implement IMemento interface for my aggregates
  3. Create a factory method of these memento objects in my aggregates
  5. Create a service that has the snapshooting policies. The snapshots are added to the NEventStore through its method. The following are very naïve code, but it’s ok for this exercise
  7. Add the snapshooting policy to the process (after events commit is done). That’s no code for production, but it helps to understand how a real snapshooting policy could be realized
  9. Finally, modify the AggregateFactory to create a new Aggregate instance from last snapshot retrieved by NEventStore

All the code is published on this commit.

blog comments powered by Disqus