2 min read

Workflow Definitions and Executions with Temporal

In the realm of distributed systems, managing and orchestrating workflows efficiently is crucial. This blog post delves into these concepts, contrasting them with state-based execution engines, and highlighting the advantages of using Temporal for building reliable and scalable distributed applications.

Workflow Definitions and Executions

Workflow definitions can be thought of as the blueprints for workflows, similar to classes in object-oriented programming. On the other hand, workflow executions are the instances of these definitions, akin to objects created from classes. Understanding this distinction is vital for grasping how workflows function in distributed systems. Definitions act as generators of executions, which are the instances that carry out the defined steps.

State-Based Execution Engines

State-based execution engines represent workflows graphically, making them more accessible for human interpretation, while also encoding them in a machine-readable format like JSON.

The workflow engine transforms the workflow definition into an execution upon invocation, sequentially activating and yielding control to the specified activities.

However, this model has its limitations. The workflow engine must persist in the current state and the entire environment at each step, leading to potential issues with expressiveness. The domain-specific language (DSL) used in state-based engines can impose constraints, limiting the control flow and error-handling capabilities.

graph LR A[Start] -->|Invoke| B[Activate Workflow] B --> C{Check State} C -->|State 1| D[Execute Activity Foo] D --> E[Persist State & Environment] E --> F{Check State} F -->|State 2| J[Execute Activity Buzz] J --> K[Persist State & Environment] K --> L[End]

Log-Based Execution Engines: Temporal

Temporal stands out as a log-based execution engine, providing developers with the flexibility to write code in various languages using SDKs. Workflow activities are executed and their results are assigned to local variables, offering a more intuitive and expressive way to define workflows.

Temporal generates commands for each activity and waits for the results at the await point. Unlike state-based engines, the workflow function execution is terminated after each command, with the workflow engine taking over to orchestrate the activity execution. Temporal relies on event sourcing to rebuild the state when necessary, ensuring durability and reliability.

graph TD A[Start] -->|Invoke| B[Execute Workflow from Start] B --> C{Await Point?} C -->|Yes, Result Available| D[Assign Result to Variable] D --> E[Proceed to Next Activity or End] C -->|No, Result Not Available| F[Generate Command for Activity] F --> G[Temporal Orchestrates Activity Execution] G --> H[Result Returned] H --> B

Temporal, with its log-based model, offers a more flexible and expressive way to build distributed applications, providing stronger execution guarantees and making it easier to transition from one valid state to the next. Whether you are building simple or complex workflows, understanding these concepts is key to creating reliable and scalable distributed systems.