2

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?

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
Steve B
  • 36,818
  • 21
  • 101
  • 174

2 Answers2

2

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!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • do you mean that the aggregate root is rebuilt each time a command is issued on it ? if yes, this is something I missed in the cqrs/ddd pattern (just started to learn these) – Steve B Jul 31 '11 at 15:44
  • 1
    It's event sourcing, which some frameworks (like ncqrs) throw in for free. So if you're looking at pure cqrs and ddd, event sourcing is in addition to that. I've been working with this for a bit under a year and there's still much to learn. :) – David Hoerster Jul 31 '11 at 22:37
  • I feel the benefits of such frameworks justify easily the amount of work to learn how they works. thanks – Steve B Aug 01 '11 at 04:46
  • No problem. Hope this helps. Good luck with your CQRS efforts! – David Hoerster Aug 01 '11 at 11:22
0

Snapshots are useful when your aggregate roots have a large number of events (1000+ perhaps?). But something to consider is that in most scenarios your aggregate are short lived and therefore have a small number of events; in which case snapshots can be seen as early optimisation; which isn't necessary a good thing.

Chris Moutray
  • 18,029
  • 7
  • 45
  • 66