Temporal Data Model:
Workflows, -Chains and -Runs
In this article we consider similarities and differences between 2 key concepts in Temporal:
"Workflow Chain" and "Workflow Run".
In most typical applications you will never need to dive deep into this topic. You will simply use Workflows and everything will "just work". However, Temporal experts and users of certain advanced scenarios will need to understand this space.
Technically, a Temporal workflow is a chain-sequence of one or more Workflow Runs from the initial invocation of a workflow to its eventual conclusion. Thus, a logical workflow (as in "just" workflow, or "the" workflow) is really a Workflow Chain.
A Workflow Run is single execution of the main workflow routine.
Completely executing a logical workflow from the initial invocation to the eventual conclusion involves a chain of one or more Workflow Runs.
The Temporal server orchestrates the execution of workflows by ensuring that Workers execute Workflow Runs as required to complete a Workflow Chain (aka a logical Workflow).
.NET Client SDK Data Model
- Workflow Chains are modeled by instances of type
- Workflow Runs are modeled by instances of type
In most scenarios, users only need to interact with logical workflows, i.e., with Workflow Chains via the respective
IWorkflowHandle instances. For example, when a user needs to send a signal to a workflow (or perform a query, terminate, cancel, etc...), they invoke a corresponding
IWorkflowHandle API. Under the covers, the handle automatically interacts with the current Run within the Workflow Chain represented by the handle.
Similarly, when a users polls for the result of a workflow, the respective
IWorkflowHandle API automatically "follows" the Chain until the "final" Run of a chain completes.
However, in some advanced scenarios users need to explicitly interact with a specific Run within the Workflow Chain representing a particular logical workflow. This is done using a
Examples that demonstrate how to do that can be found in this sample.
Specific Workflow Runs within Workflow Chains:
As discussed above, a Temporal workflow is a Chain of one or more Workflow Runs. Such a Workflow Chain spans from the initial invocation of a workflow to its eventual conclusion. A Chain may include many Runs, however, some of the Runs have a special significance:
The FIRST Run of a Chain is the Run that was initiated when the logical workflow was started.
Typically, the first Run is used to IDENTIFY the entire chain. I.e., the workflow-run-id of the first Run within a Workflow Chain identifies not only that particular Run, but also the Workflow Chain as a whole.
The LATEST Run of a Chain is the Run that has started most recently.
Such LATEST Run is sometimes also termed CURRENT. However, technically, the latest Run may have a
Runningstatus (then the entire Chain is also said to be Running) or it may already have concluded (then the entire Chain is said to be concluded). To account for this, the .NET Workflow Client SDK uses the term LATEST rather than CURRENT.
The FINAL Run of a Chain is the Run that concludes the Chain. No further Runs are known to follow after the final Run of a given Workflow Chain. In most scenarios it is not known with what Status a Run will conclude, until it does so. Therefore, a workflow may not have a final Run until it eventually concludes.
Examples for addressing specific Runs within a workflow can be found here.