Search code examples
snapshotcqrsncqrs

Benefits of Ncqrs snapshots?


In preparation of a future application design, I've started some investigations on CQRS-style applications and especially Ncqrs.

While most concepts are quite clear, I'm a bit confused by the concept of a snapshot.

I can see why rebuilding an object from its events can be highly resource-consuming, but as the denormalizer will build the read model with the latest state of the entity (or actually the latest values required for a view), why bother with the concept of rebuilding the object from snapshots?

Am I right to think such scenarios occur only sporadically and on-demand, mostly after upgrading a version or debugging?

If not, what would be good situations for taking a snapshot?


Solution

  • I have to admit I'm not a big user of event sourcing (or at least, I don't take advantage of it to its fullest extent), but snapshotting helps with the performance of your system when rebuilding the aggregate. Instead of rebuilding all events from time 0, you only need to rebuild back to the last snapshot. So if you have a high number of events in your system and having your event sourcing rebuild your aggregate is starting to affect performance of your command side, you may consider using snapshots.

    Check out notes from a Greg Young DDD/CQRS class he taught last year or so; it may give you some ideas of where he's coming from regarding snapshots.

    Hope this helps. Good luck!