daniel-smith / domain-lib

2 stars 1 forks source link

Support saving snapshot of aggregate state #14

Closed jonclare closed 3 years ago

jonclare commented 4 years ago

This could conceivably be done in another EventStoreDB stream. When snapshotting is requred, the aggregate state can be serialized in a similar way to event serialization and written to a stream. Stream metadata can be set to prune historical snapshots if the number of snapshots becomes too large.

Then, when reading, the latest event from the snapshot stream can be read before fetching the events to bring the aggregate state to the latest version.

Note that we will need a way of maintaining the maximum event number contained within the snapshot when saving the data, so as to be able to fetch this information and get only the events after this event number when loading.