Whats considered best practice to take Snapshots of the aggregates when using EventStore and CommonDomain (Is there a better place to ask, usergroup, something like that) ?
1 Answers
Stack Overflow is the best place for questions because everyone can benefit from the answers.
Snapshots should generally be taken "out of band"--that is out of the mainline of processing. In other words, when a series of events are being committed, you don't want to take a snapshot at that point. Instead, you'll want to have another thread or process take a snapshot asynchronously. I recommend another thread instead of a completely separate process because you don't have to worry about making sure your assemblies (domain, message, etc.) are the same as that for your main processing threads.
The code for "how" to take a snapshot is left up to you, the end user. I will very likely provide some additional guidance in the next week or so on the exact steps for taking a snapshot.
One additional consideration is, do you really need snapshotting? How many streams do you have that go above 1000 events? If none, then you almost certainly don't need the complexity of snapshotting.

- 5,207
- 32
- 31
-
it is clear to take snapshot outside the main processing and to not include its complexity when not needed (as stated in your excellent docs). but i have troubles about the whole api thing: there is a method GetStreamsToSnapshot, but how can i access the configured IPersistStreams? also how can i get the type of the aggregate out of its returned value IEnumerable
, for loading the aggregate with EventStoreRepository for getting its snapshot? where will you provide the guidience, your blog? – andy Apr 23 '11 at 19:00 -
The API for saving snapshots needs a small amount of work that I'll be taking care of tomorrow. To load a snapshot, the OptimisticEventStore has a separate method: GetSnapshot which returns a snapshot, if found. From there, simply call GetFrom() and pass in the snapshot. Snapshots can be kept in memory so they don't need to be loaded each time. In fact, in a ultra low-latency systems you'll want most everything in memory so that you're only ever writing to event storage. – Jonathan Oliver Apr 26 '11 at 00:56
-
The most recent commit exposes GetStreamsToSnapshot on the IStoreEvents interface and it's primary implementation, OptimisticEventStore: https://github.com/joliver/EventStore/commit/2ac284ad99f1408e5665dfcf654e575c19932794 – Jonathan Oliver Apr 27 '11 at 03:02
-
"also how can i get the type of the aggregate out of its returned value IEnumerable
, for loading the aggregate with EventStoreRepository for getting its snapshot?" – Chris Martin Jun 05 '11 at 22:51 -
When call GetStreamsToSnapshot it gives you a set of all streams that should be snapshot. From there, it's just a matter of loading the aggregate as you would normally. – Jonathan Oliver Jun 08 '11 at 14:50
-
1I don't have access to the type of aggregate to load from StreamHead. :( – Chris Martin Jun 08 '11 at 20:17