Workflow Id and Run Id
This page discusses the following:
- Run Id
- Operations leading to non-determinism
- Workflow Id
- Workflow Id Reuse Policy
- Workflow Id Conflict Policy
Each Workflow Execution is associated with a user-defined Workflow ID, a value which typically carries some business meaning (such as an order number or customer number). Temporal guarantees that there can at most one Workflow Execution with a given ID running at any point in time, a constraint that helps to protect against unexpected duplication. In some cases, such as when running the same Workflow at recurring intervals using the Schedules features, there can be multiple "runs" of a single Workflow Execution over a period of time. In this case, all runs will have the same Workflow ID. However, each run will have a unique system-generated Run ID.
What is a Run Id?
A Run Id is a globally unique, platform-level identifier for a Workflow Execution.
The current Run Id is mutable and can change during a Workflow Retry. You shouldn't rely on storing the current Run Id, or using it for any logical choices, because a Workflow Retry changes the Run Id and can lead to non-determinism issues.
Temporal guarantees that only one Workflow Execution with a given Workflow Id can be in an Open state at any given time. But when a Workflow Execution reaches a Closed state, it is possible to have another Workflow Execution in an Open state with the same Workflow Id. For example, a Temporal Cron Job is a chain of Workflow Executions that all have the same Workflow Id. Each Workflow Execution within the chain is considered a Run.
A Run Id uniquely identifies a Workflow Execution even if it shares a Workflow Id with other Workflow Executions.
Which operations lead to non-determinism issues?
An operation like ContinueAsNew
, Retry
, Cron
, and Reset
creates a Workflow Execution Chain as identified by the first_execution_run_id
.
Each operation creates a new Workflow Execution inside a chain run and saves its information as first_execution_run_id
.
Thus, the Run Id is updated during each operation on a Workflow Execution.
- The
first_execution_run_id
is the Run Id of the first Workflow Execution in a Chain run. - The
original_execution_run_id
is the Run Id when theWorkflowExecutionStarted
Event occurs.
A Workflow Reset
changes the first execution Run Id, but preserves the original execution Run Id.
For example, when a new Workflow Execution in the chain starts, it stores its Run Id in original_execution_run_id
.
A reset doesn't change that field, but the current Run Id is updated.
Because of this behavior, you shouldn't rely on the current Run Id in your code to make logical choices.
Learn more
For more information, see the following link.
What is a Workflow Id?
A Workflow Id is a customizable, application-level identifier for a Workflow Execution that is unique to an Open Workflow Execution within a Namespace.
A Workflow Id is meant to be a business-process identifier such as customer identifier or order identifier.
The Temporal Platform guarantees uniqueness of the Workflow Id within a Namespace based on the Workflow Id Reuse Policy.
A Workflow Id Reuse Policy can be used to manage whether a Workflow Id from a Closed Workflow can be re-used.
A Workflow Id Conflict Policy can be used to decide how to resolve a Workflow Id conflict with a Running Workflow.
A Workflow Execution can be uniquely identified across all Namespaces by its Namespace, Workflow Id, and Run Id.