Let’s think about how we find the event that triggered the current Saga.
Saga: a series of events (or slices of work) that where triggered by an external event and then continue to trigger next events through orchestration or choreography.
Some external trigger, such as an API call or ServiceBus event, will trigger our system to start working. This can result in one or more slices of work being executed and therefore one or more events to be recorded in our event store.
The first event we store should contain everything we will ever need to know about the external trigger.
This event needs 3 fields in addition to the information that we need about the external trigger.
– Id (a unique id for this event)
– CausationId (The id of the immediate predecessor event)
– CorrelationId (The id of first event in the saga)

On this first event in the Saga, the Id, CausationId, and CorrelationId are all equal:
CausationId1 = CorrelationId1 = Id1 = new UUID()
Each event in the saga after this will follow this pattern:
Id = new UUID()
CausationIdId n–1
CorrelationIdId1
In other words:
The next events in the saga will have the following values:
– Id (a unique id for this event)
– CausationId (The id of the immediate predecessor event)
– CorrelationId (The id of first event in the saga)
If at any point, we need to get information about the original event in this saga, and the external trigger, then we can use the ‘CorrelationId’ of the current event to get that original event in the saga.
If we need to know about the previous event then it will the ‘CausationId’ that we use to load the event and inspect it.
Just remember that Causation is a direct cause of this event. Correlation is further removed and less direct, but in this case is the origin of saga.

Leave a comment