Hi all.
Suppose this scenario. A user invokes several commands on a aggregate, like
- Create Process
- Add Line
- Add Line
- Add Comment
- Commit Work
Process will contain 2 Lines and 1 Comment. After a while it does some more work.
-
Restart Process
-
Add Line
-
Add Comment
-
Add Comment
-
Cancel Work
At this time, I need my Process to still have the same 2 Lines and 1 Comment and not 3 Lines and 3 Comments. However, the events are already there, so they must be true.
How can I achieve this? I know one way is to have a Saga sending compensation actions, like
-
Remove Line
-
Remove Comment
-
Remove Comment
But that will require lots’ of effort since for every action will have to be a counter-action, which may not always be possible.
Another way I thought it to manage manually the UnitOfWorks to span several commands/events, but this feels like opening a can of worms…
And still another way will be to use Snapshots. So the the process will be
-
Create Process
-
Add Line
-
Add Line
-
Add Comment
-
Commit Work
-
Create Snapshot
-
Restart Process
-
Add Line
-
Add Comment
-
Add Comment
-
Cancel Work
-
Reload Snapshot
This looks good in theory, but I never worked with Snapshooting, and I have several doubts about it, for instance, when we create a Snapshot the Events are deleted or they will stay in the EvenStore? How will Snapshooting play when replaying events? How can I make sure that external listeners won’t listen to the Events that were “cancelled”?
Any help much appreciated.
Cheers.