Claim Check

Capture time-variant data as snapshots for subsequent use.

Problem

Consider the event model in figure 1, where a MessageProcessor is consuming pending messages from an external system and translates them into internal requests. In doing so the MessageProcessor fetches "reference data" that is to be used later in the business flow:

figure 1

Figure 1 - Fetch time-variant data for later use

There is a requirement that the data is "freezed" immediately upon retrieval, as subsequent processing is dependent on the time-specific values.

If the captured data needs to be part of the historical record it’ll typically be included in an event, for example RequestInitiated. However, if it’s only used by Processors to make a decision about the next command and its inputs, or the payload size is exceedingly large, another approach is needed, especially to avoid passing the reference data via commands and events throughout the business flow.

Solution

Explicitly store a snapshot of fetched reference data and access it via a read model:

figure 2

Figure 2 - Fetch, store, and access a snapshot of time-variant data

Example

In listing 1 the MessageProcessor calls an API endpoint that performs the fetching and snapshotting of reference data before sending the InitiateRequest command:

// implementation of the snapshot state change/view slices in the API 
// endpoint for initiating a request:

// use the generated request ID as a claim check token.
var requestId = "<UUID>";

externalService.fetchData()
    .thenCompose(referenceData ->
        snapshotService.storeSnapshot(
            requestId,
            referenceData
        )
    )
    .thenRun(() ->
        commandGateway.send(
            new InitiateRequestCommand(requestId)
        )
    )

Listing 1 - Fetch and storing a snapshot of reference data

A note about the role of a Processor

There’s occassionally a bit of confusion about the responsibilities a Processor has in Event Modeling; for the purposes of this playbook a Processor has the following role:

Make a determination about what the next command to send should be (and therefore the potential next state transition), and collect the requisite inputs for that command.

The data that the Processor can gather for its decision-making and command inputs are:

  • Results from querying one or more read models, such as the PendingRequests and Snapshots read models above.

  • External reference data that is time-invariant.

  • Any internal static values.