Aggregating data from multiple eventual conistent bounded contexts that participate in a workflow

I am wondering what the recommended solution architecture is in cases where we allow a user to query data that is created within a temporal managed workflow.

Given the situation that multiple bounded contexts participate within a workflow to create an order in a setup where humans interact with the system triggering signals and query’ing data to obtain the current state of their order I wonder what would be the solution architecture to ensure a user will see a consistent state of their order.

Consistent meaning that querying the bounded contexts will result in data that guarantees that all results from the bounded contexts point to mutation X so that to sum of the parts present a fully consistent order state.

I can imagine many solutions here but I wonder what the most appropriate way is to deliver this consistency on query level with Temporal is.

Workflow is fully consistent. So you can use it as a source of truth about the system. Query workflow for the current state of the order.

Hi @maxim, thank you for responding.

If N activities from within the workflow interact with separate systems that store data in their own storage backend and, due to reasons, cannot store the partial order states in the workflow, what do you believe are the patterns I can apply to get a consistent result.

My current perception is that I will need another mechanism to guarantee consistency when querying the N storage systems, like for example versioning, as Temporal is not able to help with consistency on the external reads, is this correct?

Regards, Frank

I don’t understand what you mean by “consistent result.” If you have separate systems that store data, you cannot, by definition, have a “consistent” result as their storage is not transactionally consistent.

Indeed, this is exactly the challenge we’re trying to find a best solution for.

As we’re legally obliged to show a state where all transactional boundaries are at the same version of their subset of order, or, we at least show the same version of the order being created during the workflow, I see roughly 2 options we have to implement this

  1. All contexts store a version, which is managed by the worfklow. When we send a signal to Temporal the workflow will guarantee that either all writes to the transactional boundaries succeed or compensating actions are executed to ensure they eventually reach the same consistent state. The query after signal guarantee will help when they store their state and we query for an order with version X on all contexts to assemble an order at version X to expose to consumers, where the version helps us to show an order where all contexts are consistent as we can use Temporal to orchestrate the writes and query only when things are consistent over the N transactional boundaries,

  2. we store the states of the contexts in the workflow during the execution of an activity so that we can get the latest version of an order X directly from the workflow, which would be very convenient in many regards but I am not sure this is a good pattern to use?

Given the 2 scenarios, would/could you recommend one or perhaps offer an alternative to use Temporal most optimally?

Both options work. (2) is simpler, assuming the state is small enough to be part of the workflow.

1 Like