I. What Is an AI Workflow?
An AI workflow (AI Workflow) is a system mechanism that combines AI model capabilities with program logic, external tools, data resources, and business rules, and follows a predefined or dynamically generated execution path to complete one or more complex tasks.
Traditional programs usually rely on developers explicitly writing execution logic, whereas AI workflows can delegate some decisions to large models, enabling the system to understand natural language, dynamically select tools, generate content, and process unstructured information.
For example, an intelligent contract review workflow can include:
- Receive the contract uploaded by the user.
- Parse PDF, Word, and other documents.
- Extract key information such as contract parties, amounts, and terms.
- Retrieve relevant legal provisions and internal corporate policies.
- Call a large model to identify risks.
- Perform rule-based validation on the identified risks.
- Generate a review report.
- Save the results to the business system.
These tasks are not simply a series of model calls; rather, they form a complete execution process organized through explicit nodes, data-passing rules, and control logic.
1. Core Components of an AI Workflow
A typical AI workflow usually includes the following components:
| Component | Main Responsibility |
|---|---|
| Trigger | Start the workflow, e.g., a user request, scheduled task, or Webhook |
| Input | Receive data such as text, files, and structured parameters |
| Node | Execute an individual task |
| LLM Model | Understand, reason, classify, and generate content |
| Tool | Call search, databases, APIs, or business services |
| Condition | Determine the subsequent path based on execution results |
| State | Store context and intermediate data during workflow execution |
| Loop | Repeat certain tasks until the exit condition is met |
| Output | Return the final result or perform business operations |
| Error Handler | Handle timeouts, failures, retries, and degradation |
2. Basic Execution Process of an AI Workflow
A simple AI workflow can be abstracted as:
flowchart TD
A["Trigger workflow"] --> B["Receive input"]
B --> C["Execute task node"]
C --> D["Call AI model"]
D --> E["Parse model result"]
E --> F{"Are execution conditions met?"}
F -->|"Yes"| G["Execute subsequent tasks"]
F -->|"No"| H["Enter exception handling or supplementary processing"]
G --> I["Generate final result"]
H --> I
I --> J["Output result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#F7EAE7,stroke:#C98D7C,color:#754438
style I fill:#EAF3EC,stroke:#83A995,color:#315D49
style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Note: Not every node in an AI workflow necessarily calls a large model. Tasks such as data reading, format conversion, conditional checks, permission checks, and database writes are usually better handled by deterministic program logic.
II. Differences Between AI Workflows and Traditional Workflows
Traditional workflows mainly address business process automation, such as approvals, order processing, data synchronization, and task scheduling.
AI workflows, by contrast, introduce large-model capabilities on top of traditional process orchestration, enabling some tasks to be executed dynamically based on natural language, unstructured data, and context.
1. Traditional Workflows
Traditional workflows usually use predefined rules and fixed execution paths.
For example, an order approval process:
flowchart TD
A["Submit order"] --> B["Check order amount"]
B --> C{"Does amount exceed threshold"}
C -->|"No"| D["Auto-approve"]
C -->|"Yes"| E["Manager approval"]
E --> F{"Is approval granted"}
F -->|"Yes"| G["Create order"]
F -->|"No"| H["Reject order"]
D --> G
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style H fill:#F7EAE7,stroke:#C98D7C,color:#754438
Characteristics:
- The execution path is defined in advance.
- Decision conditions are explicit.
- The same input usually produces the same execution path.
- Suitable for businesses with clear rules and stable processes.
- No inherent semantic understanding or open-ended reasoning capability.
2. AI Workflows
AI workflows allow large models to participate in task understanding, classification, information extraction, and path selection.
For example, an intelligent customer service process:
flowchart TD
A["Receive user question"] --> B["LLM understands intent"]
B --> C["Identify question type"]
C --> D{"Question type"}
D -->|"Order issue"| E["Query order system"]
D -->|"Product issue"| F["Search product knowledge base"]
D -->|"Technical issue"| G["Search technical documentation"]
E --> H["Compile query results"]
F --> H
G --> H
H --> I["LLM generates answer"]
I --> J["Output to user"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style C fill:#EAF3EC,stroke:#83A995,color:#315D49
style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style H fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style I fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style J fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Characteristics:
- Capable of understanding natural language and unstructured input.
- Can identify task types based on semantics.
- Can invoke different tools and external systems.
- Can adjust part of the execution path based on intermediate results.
- Requires additional handling of the uncertainty in model outputs.
3. Core Differences Between the Two
| Comparison Dimension | Traditional Workflow | AI Workflow |
|---|---|---|
| Decision-making method | Fixed rules | Combination of rules and model decisions |
| Input format | Mainly structured data | Structured and unstructured data |
| Execution path | Predefined | Fixed path or dynamic branching |
| Semantic understanding | Usually absent | Achievable via large models |
| Tool invocation | Fixed interface calls | Can be dynamically selected in combination with models |
| Result determinism | Relatively high | Affected by model output |
| Interpretability | Usually strong | Requires additional design for decision records |
| Applicable scenarios | Approval, orders, scheduling | Intelligent customer service, knowledge processing, content generation |
The two are not mutually substitutive.
In production systems, a hybrid architecture is usually adopted: deterministic business logic is handled by traditional workflows, while semantic understanding, content generation, and complex judgments are left to AI models.
III. Core Architecture of AI Workflows
An AI workflow is not simply chaining multiple model calls together; it is a runtime system equipped with an execution engine, state management, task orchestration, and exception recovery capabilities.
1. Overall Architecture
A reasonably complete AI workflow system can be divided into six layers:
| Architecture Layer | Core Responsibility |
|---|---|
| Access Layer | Receive user requests, webhooks, and scheduled tasks |
| Orchestration Layer | Parse workflow definitions and schedule node execution |
| Execution Layer | Execute LLM, tool, code, and business nodes |
| State Layer | Store workflow instances, node states, and context |
| Integration Layer | Connect to databases, APIs, vector stores, and external services |
| Observability Layer | Record logs, metrics, traces, and execution events |
flowchart TB
A["Access Layer<br/>API / Webhook / Scheduler"]
B["Workflow Orchestration Layer<br/>Workflow Engine"]
C["Node Execution Layer<br/>Node Executor"]
D["State Management Layer<br/>State / Context / Checkpoint"]
E["External Integration Layer<br/>LLM / Tools / Database"]
F["Observability Layer<br/>Logs / Metrics / Traces"]
A --> B
B --> C
C --> D
C --> E
B --> F
C --> F
D --> B
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style D fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style E fill:#EAF3EC,stroke:#83A995,color:#315D49
style F fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
How the layers relate to one another:
- The access layer is responsible for creating workflow instances.
- The orchestration layer is responsible for determining the order of node execution.
- The execution layer is responsible for actually executing node logic.
- The state layer is responsible for saving data generated during execution.
- The integration layer provides access to external models and business systems.
- The observability layer is responsible for recording how the workflow runs.
2. Workflow Definitions and Workflow Instances
This is a very important pair of concepts for understanding workflow systems.
Workflow Definition
Describes how a workflow should be executed, and usually includes:
- Node definitions.
- Dependencies between nodes.
- Input and output schemas.
- Conditional branches.
- Loop rules.
- Timeout and retry policies.
- Exception handling policies.
Workflow Instance
Represents one specific execution, and usually includes:
- Instance ID.
- Current execution state.
- Input parameters.
- Intermediate results.
- Node execution records.
- Error messages.
- Start time and end time.
For example, the same contract review workflow definition can be used to create multiple instances at the same time, each handling a contract uploaded by a different user.
Workflow definition: Contract review process
├── Instance A: Review task for Contract A
├── Instance B: Review task for Contract B
└── Instance C: Review task for Contract C
A workflow definition is usually relatively stable, whereas workflow instances have independent lifecycles and runtime states.
3. Nodes and Edges
A workflow can usually be abstracted as a directed graph:
Where:
- V: the set of nodes, where each node represents an execution unit.
- E: the set of edges, representing dependencies or control relationships between nodes.
For example:
flowchart TD
A["Input Node"] --> B["Document Parsing"]
B --> C["Information Extraction"]
C --> D["Risk Analysis"]
D --> E["Report Generation"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Nodes are responsible for execution, and edges describe execution relationships.
Edges can express not only simple sequential dependencies, but also conditions, for example:
- Execute a downstream node only if the upstream node succeeds.
- Enter a specific branch when a certain field meets a condition.
- Execute a downstream node only after multiple upstream nodes have all completed.
- Select different nodes based on dynamic routing results.
For complex workflows, graph structures make it easier to express parallelism, branching, and loops than simple linear task lists.
IV. Core Node Types in AI Workflows
Workflow nodes are the basic units that make up the entire execution system. Different nodes have different responsibilities, and nodes are connected through input and output data.
1. Input Node
Responsible for receiving the data required for workflow execution.
Common inputs include:
- User text.
- Files.
- JSON parameters.
- API requests.
- Database records.
- External events.
For example:
{
"user_id": "U10001",
"question": "如何申请退款?",
"channel": "web"
}
Input nodes require Schema validation to prevent downstream nodes from receiving incomplete or incorrectly typed data.
2. LLM Node
Responsible for calling a large language model to complete semantic tasks.
Common tasks:
- Text classification.
- Information extraction.
- Content generation.
- Summarization.
- Intent recognition.
- Reasoning analysis.
- Structured output.
For example, using a model to identify the type of user question:
Input:
"My order has already shipped; can I cancel it?"
Model output:
{
"intent": "cancel_order",
"confidence": 0.93,
"requires_order_lookup": true
}
Note that even if the JSON output by the model is syntactically correct, it does not mean the business conclusion is necessarily correct. For key fields, Schema validation, enum validation, and business rule validation should be performed.
3. Tool Node
Responsible for calling external tools or business APIs.
For example:
- HTTP API.
- Database queries.
- Search engines.
- Vector databases.
- File systems.
- Enterprise internal business services.
- Tools provided by an MCP Server.
The model is responsible for understanding the task and proposing calls, while actual tool execution is usually performed by the workflow execution engine or application service.
4. Code Node
Responsible for executing deterministic program logic.
For example:
- Data transformation.
- Field mapping.
- Date calculations.
- Numerical calculations.
- Format validation.
- Rule-based decisions.
- Data cleaning.
Tasks that can be completed accurately with ordinary code should not be forced through a large model just to use AI.
5. Condition Node
Determines the execution path based on conditions.
For example:
flowchart TD
A["Get model classification result"] --> B{"Does confidence meet the threshold?"}
B -->|"Yes"| C{"Does it require manual handling?"}
B -->|"No"| D["Go to manual review"]
C -->|"Yes"| D
C -->|"No"| E["Automatically execute subsequent tasks"]
D --> F["Manual review"]
E --> G["Output processing result"]
F --> G
style A fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style B fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#EAF3EC,stroke:#83A995,color:#315D49
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Condition nodes should prioritize explicit rule-based decisions. When model confidence is involved, you also need to consider whether the confidence has been calibrated; you cannot simply treat the model's self-reported value as a true probability.
6. Loop Node
Responsible for repeatedly executing a set of tasks.
Common scenarios:
- Batch processing files.
- Iterating over retrieval results.
- Analyzing data one by one.
- Multi-round generation and validation.
- Agent repeatedly calling tools.
Loops must have clear exit conditions to avoid infinite execution.
7. Human-in-the-Loop Node
Also called a human intervention node, it is used to hand some decisions over to humans.
Typical scenarios:
- Confirmation of high-risk operations.
- Review of AI-generated content.
- Review of anomalous data.
- Financial approval.
- Confirmation before contract signing.
Human intervention usually puts the workflow into a waiting state, where it resumes execution only after an external review result is submitted.
8. Output Node
Responsible for organizing and outputting the final result.
Possible output methods include:
- Return an API response.
- Generate a file.
- Write to a database.
- Send email or messages.
- Update a business system.
- Publish task execution events.
Output nodes should define clear success criteria; the completion of a single upstream node should not be taken as success of the entire business task.
V. Key Execution Mechanisms of AI Workflows
After understanding node types, you also need to understand how the workflow engine schedules nodes, passes data, and manages execution state.
1. Node Scheduling Mechanism
Whether a node can execute usually depends on whether its dependent nodes have met their execution conditions.
For a simple Directed Acyclic Graph (DAG), the execution engine can determine executable nodes based on topological sorting.
For example:
flowchart TD
A["Start"] --> B["Read user info"]
A --> C["Read order info"]
B --> D["Generate analysis result"]
C --> D
D --> E["Output result"]
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
Among them, B and C do not depend on each other, so they can execute in parallel.
D depends on B and C, and can only execute after both nodes have met their completion conditions.
The actual scheduling process can be abstracted as:
- Create a workflow instance.
- Initialize node states.
- Find all nodes whose dependencies have been satisfied.
- Put executable nodes into the scheduling queue.
- Execute node tasks.
- Update node status and output.
- Recalculate whether downstream nodes meet execution conditions.
- End the workflow after all termination conditions are met.
Note that topological sorting is suitable for describing DAG workflows, but for systems containing loops, dynamic routing, and waiting for human input, additional state machines or graph execution mechanisms are needed.
2. Data Passing Mechanism
Data needs to be passed between nodes.
Common data passing patterns include:
Explicit Input/Output
Each node declares input fields and output fields, and downstream nodes obtain data through field references.
Shared Context
The workflow instance maintains a unified context, and nodes read data from the context and write results to designated namespaces.
State Snapshot
Persist the state before and after node execution to support resumption and historical tracking.
For example:
{
"workflow_id": "contract_review",
"instance_id": "run_001",
"state": {
"input": {
"file_id": "file_001"
},
"parsed_document": {
"text": "合同正文..."
},
"risk_analysis": {
"risk_level": "high"
}
}
}
Although shared state is convenient, if multiple parallel nodes modify the same field simultaneously, it may cause overwriting, race conditions, and data inconsistency problems.
Production environments should clarify:
- Node input/output boundaries.
- Field ownership.
- Parallel write strategy.
- State version.
- Data serialization rules.
- Sensitive data storage strategy.
3. State Management Mechanism
A workflow is not a simple function call. Complex workflows may last seconds, minutes, or even hours.
Therefore, the lifecycle states of workflows and nodes need to be maintained.
Common workflow states:
| State | Meaning |
|---|---|
| Pending | Waiting to execute |
| Running | Executing |
| Waiting | Waiting for external events or human input |
| Completed | Successfully completed |
| Failed | Execution failed |
| Cancelled | Cancelled |
| Paused | Paused |
Node states usually also need to distinguish between:
- Not scheduled.
- Queued.
- Executing.
- Waiting for retry.
- Executed successfully.
- Execution failed.
- Skipped.
- Cancelled.
State transition diagram:
flowchart TD
A["Pending"] --> B["Running"]
B -->|"Execution succeeded"| C["Completed"]
B -->|"Execution failed"| D{"Is retry allowed?"}
D -->|"Yes"| E["Retry Waiting"]
E --> B
D -->|"No"| F["Failed"]
B -->|"Waiting for manual input"| G["Waiting"]
G --> B
B -->|"Cancellation requested"| H["Cancelled"]
style A fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
style G fill:#EAF3EC,stroke:#83A995,color:#315D49
style H fill:#F7EAE7,stroke:#C98D7C,color:#754438
A state machine can prevent illegal state transitions; for example, a node that has already reached Completed cannot directly change back to Running without explicit re-execution semantics.
4. Workflow Persistence and Checkpoint Recovery
If a workflow is kept only in process memory, then service restarts, machine failures, or container migrations may cause tasks to be lost.
Therefore, production-grade workflow engines usually need to persist:
- Workflow definition version.
- Workflow instance state.
- Node execution state.
- Node inputs and outputs.
- Retry count.
- Waiting event information.
- Execution history.
- Checkpoint.
The core idea of checkpoint recovery is to start from the most recent reliable state snapshot and determine which nodes have already completed and which nodes need to be re-executed.
flowchart TD
A["Workflow execution"] --> B["Node execution completed"]
B --> C["Persist node result"]
C --> D["Save Checkpoint"]
D --> E{"Is the process healthy?"}
E -->|"Yes"| F["Continue executing subsequent nodes"]
E -->|"No"| G["Reload workflow state"]
G --> H["Restore latest Checkpoint"]
H --> I["Identify incomplete nodes"]
I --> F
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style D fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style G fill:#F7EAE7,stroke:#C98D7C,color:#754438
style H fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style I fill:#EAF3EC,stroke:#83A995,color:#315D49
There is a key issue here:
Recovering a workflow is not the same as directly resuming execution from the checkpoint.
If a process crashes after a node calls an external payment API but before the execution result is written to the Checkpoint, recovery may call the payment API again.
Therefore, it is necessary to combine:
- Idempotency keys.
- External operation status queries.
- Transactions or the Outbox pattern.
- Execution records.
- Compensating actions.
to prevent recovery execution from producing duplicate side effects.
6. Exception Handling and Failure Recovery in AI Workflows
The sources of failure in AI workflows are more complex than in traditional workflows.
In addition to network, database, and program exceptions, issues such as model output not conforming to the Schema, incorrect tool selection, context length overruns, and unreliable generated content may also occur.
1. Common Exception Types
| Exception Type | Typical Symptom | Handling Method |
|---|---|---|
| Model invocation failure | API timeout, rate limiting, service unavailable | Retry, switch model, fallback |
| Output format error | Invalid JSON, missing fields | Schema validation, controlled repair |
| Tool execution failure | API returns error, insufficient permissions | Error classification, retry or terminate |
| Data anomaly | Corrupted file, missing fields | Input validation, isolation handling |
| Workflow timeout | Node or entire task takes too long | Timeout control, cancel execution |
| State persistence failure | Checkpoint write failure | Pause progress, restore consistency |
| Business rule failure | Insufficient quota, approval not passed | Business branch or manual handling |
2. Exception Handling Process
flowchart TD
A["Node starts execution"] --> B["Execute model or tool"]
B --> C{"Execution successful?"}
C -->|"Yes"| D["Validate output result"]
D --> E{"Is result valid?"}
E -->|"Yes"| F["Save result and continue"]
E -->|"No"| G["Output validation failed"]
C -->|"No"| H["Identify exception type"]
G --> H
H --> I{"Is retry allowed?"}
I -->|"Yes"| J["Wait for backoff time"]
J --> B
I -->|"No"| K{"Is fallback allowed?"}
K -->|"Yes"| L["Execute fallback strategy"]
K -->|"No"| M["Mark as failed and log"]
L --> F
style A fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style B fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style C fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style D fill:#EAF3EC,stroke:#83A995,color:#315D49
style E fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style F fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style G fill:#F7EAE7,stroke:#C98D7C,color:#754438
style H fill:#F5F8F4,stroke:#B5CBBB,color:#40594A
style I fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style J fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style K fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style L fill:#EAF3EC,stroke:#83A995,color:#315D49
style M fill:#F7EAE7,stroke:#C98D7C,color:#754438
3. Retry Mechanism
Retry mechanisms are suitable for handling transient failures, such as:
- Network connection interruption.
- HTTP 429 rate limiting.
- Server temporarily unavailable.
- Request timeout.
A common strategy is exponential backoff:
Where:
- t_n: Wait time before the nth retry.
- t_0: Initial wait time.
- t_{\max}: Maximum wait time.
- J: Random jitter (Jitter).
Random jitter can reduce traffic spikes caused by many tasks retrying at the same time.
Retries cannot be performed unconditionally. For deterministic errors such as parameter errors, permission denial, and unmet business rules, repeated retries are usually meaningless.
4. Fallback Mechanism
When the primary model or primary tool is unavailable, a fallback strategy can be used.
For example:
- Switch to a backup model after the primary model fails.
- Switch to a lightweight model when the high-quality model is unavailable.
- Use cached results when real-time retrieval is unavailable.
- Transfer to manual handling when AI classification fails.
- Return basic query results when non-critical summary generation fails.
Fallback must clearly define quality boundaries. The system must not output unverified data as trustworthy results just because it needs to return a result.
5. Compensation Mechanism
For nodes with external side effects, such as:
- Create an order.
- Deduct inventory.
- Initiate payment.
- Send notification.
- Modify user permissions.
If the workflow fails midway, a simple retry may cause duplicate operations.
A compensation mechanism is needed at this point, to undo or correct operations that have already completed, based on business semantics.
For example, order processing:
flowchart TD
A["Create Order"] --> B["Deduct Inventory"]
B --> C["Initiate Payment"]
C --> D{"Payment Successful?"}
D -->|"Yes"| E["Order Completed"]
D -->|"No"| F["Release Inventory"]
F --> G["Cancel Order"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#EAF3EC,stroke:#83A995,color:#315D49
style C fill:#EAE8FA,stroke:#A49BD5,color:#51477D
style D fill:#F7F4E8,stroke:#C7B77A,color:#675A2D
style E fill:#DCEFE5,stroke:#4F8B70,color:#24563F
style F fill:#F7EAE7,stroke:#C98D7C,color:#754438
style G fill:#F7EAE7,stroke:#C98D7C,color:#754438