Hi,
I'm currently trying to understand a bit more about CQRS.
Let's assume I have a command A which then leads to 3 events B,C,D. This command can be executed individually or in a bulk operation, e.g. executing let's say 1000 commands in short time on the same aggregate root.
I know that the state of the domain model during this batch command is not necessary to be calculated and I like to reduce the load on the system by skipping the calculation and e.g. the read model updates.
I've seen that a bulk event concept is used here:
http://cqrs.nu/FaqSo my idea was:
BulkCommand -> BulkStartEvent, Event B, C, D, ..., B, C, D, BulkEndEvent
I could then use a Saga to handle the Bulk Command, started by BulkStartEvent and ended by BulkEndEvent, and only update my models (both domain and read) after the End Event.
Now my question is: How do I prevent my normal Event Handlers for event B, C, D from updating the models anyway?
I have several ideas and I do not really like any of them:
- Simply ignore the problem and let the event handlers do their job anyway,
- Let my Event handlers do the updates anyway and have some nifty caching
inplace to reduce the impact on the system. I do not really like this as
this only moves the problem around a bit
- Have a fully independent set of Batch Events, just for the batch command (e.g. derive Event B' from Event B and call it BatchEventB), I do not really like this as I then get many more, fully duplicated events
- Let my Saga swallow the events B,C,D during its lifetime, e.g. setting some flag which tells my other Event handlers to ignore them. I do not really like this as I then have some kind of state connection between independent event handlers
- Decoupling/disabling the event handlers during the bulk command and reenabling them after it has ended. I do not like this, because I let a command influence my system logic, this might get really ugly in a multi user environment.
The best compromise I can think of is:
- Use 1 if the bulk command is rarely used
- Use 2 if the bulk command is used more often, the caching might be useful at other places too
- Use 3 if the bulk command has only a few events.
Any better/other ideas on how to handle it?
Best Regards,
Torni