Skip to content

Commit 436205c

Browse files
committed
perf(non-determinism): added explanation about replay without saying determinism
1 parent a44d3e5 commit 436205c

1 file changed

Lines changed: 50 additions & 22 deletions

File tree

docs/encyclopedia/workflow/workflow-overview.mdx

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ id: workflow-overview
33
title: Temporal Workflow
44
sidebar_label: Workflow
55
description:
6-
This comprehensive guide provides insights into Temporal Workflows, covering Workflow Definitions in various
7-
programming languages, deterministic constraints, handling code changes, and ensuring reliability, durability, and
8-
scalability in a Temporal Application, with examples and best practices for Workflow Versioning and development.
6+
This comprehensive guide provides insights into Temporal Workflows, covering Workflow Definitions in various programming languages, deterministic constraints, handling code changes, and ensuring reliability, durability, and scalability in a Temporal Application, with examples and best practices for Workflow Versioning and development.
97
slug: /workflows
108
toc_max_heading_level: 4
119
keywords:
@@ -25,29 +23,59 @@ This guide provides a comprehensive overview of Temporal Workflows and covers th
2523

2624
## Intro to Workflows
2725

28-
Conceptually, a workflow defines a sequence of steps. With Temporal, those steps are defined by writing code, known as a
29-
Workflow Definition, and are carried out by running that code, which results in a Workflow Execution.
26+
Conceptually, a workflow defines a sequence of steps. With Temporal, those steps are defined by writing code, known as a Workflow Definition, and are carried out by running that code, which results in a Workflow Execution.
3027

31-
In day-to-day conversations, the term Workflow might refer to Workflow Type, a Workflow Definition, or a Workflow
32-
Execution.
28+
In day-to-day conversations, the term Workflow might refer to Workflow Type, a Workflow Definition, or a Workflow Execution.
3329

3430
1. A **Workflow Definition** is the code that defines your Workflow.
35-
2. The **Workflow Type** is the name that maps to a Workflow Definition. It's an identifier that makes it possible to
36-
distinguish one type of Workflow (such as order processing) from another (such as customer onboarding).
37-
3. A **Workflow Execution** is a running Workflow, which is created by combining a Workflow Definition with a request to
38-
execute it. You can execute a Workflow Definition any number of times, potentially providing different input each
39-
time (i.e., a Workflow Definition for order processing might process order #123 in one execution and order #567 in
40-
another execution). It is the actual instance of the Workflow Definition running in the Temporal Platform.
31+
2. The **Workflow Type** is the name that maps to a Workflow Definition. It's an identifier that makes it possible to distinguish one type of Workflow (such as order processing) from another (such as customer onboarding).
32+
3. A **Workflow Execution** is a running Workflow, which is created by combining a Workflow Definition with a request to execute it. You can execute a Workflow Definition any number of times, potentially providing different input each time (i.e., a Workflow Definition for order processing might process order #123 in one execution and order #567 in another execution). It is the actual instance of the Workflow Definition running in the Temporal Platform.
4133

42-
You'll develop those Workflows by writing code in a general-purpose programming language such as Go, Java, TypeScript,
43-
or Python. The code you write is the same code that will be executed at runtime, so you can use your favorite tools and
44-
libraries to develop Temporal Workflows.
34+
You'll develop those Workflows by writing code in a general-purpose programming language such as Go, Java, TypeScript, or Python. The code you write is the same code that will be executed at runtime, so you can use your favorite tools and libraries to develop Temporal Workflows.
4535

46-
Temporal Workflows are resilient.
47-
They can run—and keep running—for years, even if the underlying infrastructure fails.
48-
If the application itself crashes, Temporal will automatically recreate its pre-failure state so it can continue right where it left off.
36+
Temporal Workflows are resilient. They can run—and keep running—for years, even if the underlying infrastructure fails. If the application itself crashes, Temporal will automatically recreate its pre-failure state so it can continue right where it left off.
4937

50-
Each Workflow Execution progresses through a series of **Commands** and **Events**, which are recorded in an **Event
51-
History**.
38+
Each Workflow Execution progresses through a series of **Commands** and **Events**, which are recorded in an **Event History**.
5239

53-
Workflows must follow deterministic constraints to ensure consistent replay behavior.
40+
### How Workflow replay works
41+
42+
When a Workflow pauses or encounters an error, the goal of Temporal is to bring the Workflow back to the exact same state it was in before the pause occurred. To make that possible, Temporal keeps the Event History. This is a complete, ordered log of everything that has already happened in a Workflow.
43+
44+
The Event History could look like this for example:
45+
46+
- Started Timer for 5 minutes
47+
- Scheduled Activity X
48+
- Activity X completed with result Y
49+
- Received Signal Z
50+
51+
This history is the source of truth for everything that happens in the Workflow.
52+
53+
#### Resuming a Workflow
54+
55+
When it's time to continue the Workflow, Temporal doesn't restore memory from a snapshot. It starts the Workflow code from the beginning, replays the Event History step by step, and uses that history to guide the code back to the exact state as before. So the Workflow code is re-run, but uses the recorded events instead of redoing work.
56+
57+
Because the Workflow is re-executed to rebuild its state:
58+
59+
- It has to make the same decisions when given the same history, which makes a Workflow deterministic.
60+
- It shouldn't depend on values that can change between runs.
61+
62+
For example:
63+
64+
- A direct call to `Date.now()` could return a different value on replay.
65+
- A random number could change.
66+
- A network call could return something new.
67+
68+
If those values changed, the Workflow could take a different path and fail to match the recorded history. To solve this, Temporal provides replay-safe versions of common operations:
69+
70+
- Time is read from the Workflow context so it matches the recorded history.
71+
- Timers are recorded as events and don’t “wait” again during replay.
72+
- Randomness and similar values can be captured once and reused.
73+
74+
These APIs make sure the Workflow receives the same values during replay as it did originally. Activities handle everything that interacts with the outside world, like:
75+
76+
- API calls
77+
- Database queries
78+
- LLM invocations
79+
- File I/O
80+
81+
When a Workflow calls an Activity, the Activity runs once, its result is recorded in the Event History. During replay, that result is reused, not recomputed. So Activities aren't executed again during replay.

0 commit comments

Comments
 (0)