I create a service using the usual event search pattern:
- Request received.
- The general story is loading.
- The unit is rebuilt (from its history).
- New events are prepared, and the unit is updated in response to an incoming request from step 1.
- These events are logged and made available (published) to all subscribers.
In my case, step 5 is performed in two parts. Events are recorded in the event log. The background process is read from the event log and publishes all events starting at the offset.
In some cases, I need to post side effects in addition to aggregate events. As for the system, these are events, because they are consumed and affect the state of other services. However, they do not affect the history of the population in this service and are not needed to restore it.
How do I handle them in code?
Option 1- Do not write side effects to the event log. Publish them in the main process until step 5.
Option 2- Write everything to the event log and ignore the side effects when loading the story. (This is not part of the story!)
Option 3- Record side effects in a fictitious aggregate so that they are published but never loaded.
Option 4-
The first option may cause problems if there is a concurrency violation. If the recording fails in step 5, a side effect cannot be easily rolled back. The second option records events that are not part of the overall story. When loading in step 2, these side effects should be ignored. The third option looks like a hack.
Which one seems right to you?
source share