I am sorry about the newbie questions; this is my first time attempting to implement an event store. Can someone please either clarify or correct my design for both snapshots and updating read models?
Is this a valid/recommended strategy?
Subscribe to all streams (in a background service)
For all events check the the stream id ignore events that do not start with a given prefix
For matching events, use a concurrentBag (hashset) to store the Id of the streams
Every 30 seconds or so, for each changed aggregate, load the aggregate replaying any events since the previous snapshot
Save the aggregate (probably in mongodb) replacing the existing version
Is this reasonable?
I think I understand how to store and retrieve snapshots based on information gleaned from previous posts. What I am not sure about is the mechanism for initiating a request to take a snapshot, given that I want to have the snapshotting itself performed within a background service. Looking at NEventStore, they have a mechanism for retrieving streams due for snapshotting (GetStreamsToSnapshot). My understanding is that EventStore does not provide a mechanism for querying streams so a different approach is required? Therefore does the following approach sound reasonable?
When loading an aggregate, check whether the number of events since the last snapshot exceeds a given threshold.
If the threshold is exceeded, initiate a TakeSnapshot message and store this on a Snapshots stream.
Subscribe to the snapshots stream in a background service.
Take the snapshots.
I don’t particularly like this approach for the following reasons:
a) A snapshot request will only be initiated on loading an aggregate. I would prefer this when writing the event but this is currently an append only operating for performance reasons (i.e. we are not loading previous events).
b) I would rather avoid creating initiate requests when loading the aggregate, preferring to have all snapshotting concerns the responsibility of the snapshot service.
The other idea I had is to use the read-model to provide the mechanism the information on the streams that exist. But this seems a bit wrong?
I am probably missing something here?