You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/encyclopedia/workflow/workflow-overview.mdx
+50-22Lines changed: 50 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,7 @@ id: workflow-overview
3
3
title: Temporal Workflow
4
4
sidebar_label: Workflow
5
5
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.
9
7
slug: /workflows
10
8
toc_max_heading_level: 4
11
9
keywords:
@@ -25,29 +23,59 @@ This guide provides a comprehensive overview of Temporal Workflows and covers th
25
23
26
24
## Intro to Workflows
27
25
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.
30
27
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.
33
29
34
30
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.
41
33
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.
45
35
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.
49
37
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**.
52
39
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