Workflow Framework with Temporal
Building resilient and scalable web workflows using the Temporal framework.
StateSet Workflow Framework with Temporal
Introduction
StateSet leverages the Temporal framework to build robust and scalable workflows. Temporal’s open-source programming model simplifies complex application logic, enhances reliability, and accelerates feature delivery. By combining serverless API calls with a deterministic execution engine, Temporal provides the backbone for automating critical business processes.
In particular, StateSet’s Return Management (RMA) process is fully automated using Temporal. This includes: generating and emailing return labels, creating return records in StateSet, facilitating record retrieval, updating customer support platforms, and processing instant refunds. This automation significantly streamlines the return process, improves customer satisfaction, and allows businesses to manage returns more efficiently.
Core Components of StateSet Workflows
StateSet Workflows are built using the following components within the Temporal framework:
- Temporal Client: The entry point for starting workflows and signaling their execution.
- Temporal Worker: Executes the workflows and activities, polling the task queue for work.
- Temporal Workflow: Defines the sequence of steps in the business process to be automated.
- Temporal Activities: Represents atomic units of work that a workflow executes.
Temporal Client: Initiating Workflows
The Temporal Client is used to start workflows, and send signals. In StateSet, the Temporal client is configured with:
- Namespace: A logical grouping of workflows. (Stateset is using the
stateset
namespace) - Task Queue: A queue that workers poll for workflows and activities. (Stateset is using
stateset-returns-automation
) - Workflow Path: The location of the Workflow definition.
Here’s an example of how Stateset’s Return API uses the Temporal Client to initiate a return workflow.
The code shows how we connect to the Temporal cluster and execute the
returnApprovedWorkflow
workflow by passing some initial arguments.
Temporal Worker: Executing Workflows and Activities
The Temporal Worker is responsible for executing workflows and activities. It polls the specified task queue for pending tasks and executes them.
Here is an example of how a worker is set up to process return workflow:
This worker is configured to pick up workflow tasks on the
stateset-returns-automation
task queue and use the code in theactivities.js
file.
Return Approved Workflow: Orchestrating the Process
The returnApprovedWorkflow
orchestrates the various steps when a return request is approved. It’s triggered by the Temporal Client, and it executes the following activities:
This workflow defines the sequence of steps to execute when a return is approved. The workflow is composed of activities which are executed by the temporal worker.
Activities: The Atomic Units of Work
Activities encapsulate the atomic units of work that a workflow executes. Here is an example of a few of the activities that we use in the workflow above. These are the actual calls that are executed by the Temporal Worker.
These activities are functions that do the actual work for the workflow. In this case they’re just logging the activity for the sake of example. In a production system, these functions would call our APIs to perform business logic
Stateset Cloud: Hosted Temporal
StateSet provides a hosted Temporal workflow service with deterministic execution and state-of-the-art infrastructure. The hosted service can be accessed at https://cloud.stateset.com.
This diagram shows the different parts of the temporal framework and how they’re organized.
Conclusion
By leveraging the Temporal framework, StateSet implements complex workflow orchestration in a safe, reliable, and scalable way. The separation of concerns between workflows and activities enables StateSet to develop complex features quickly while relying on the powerful Temporal platform.