How To Visualize Temporal.io Workflows
Temporal is a great workflow engine. This project demonstrates how temporal can be enhanced to provide a visual representation of workflows.
Join the DZone community and get the full member experience.Join For Free
I hope everyone knows about Temporal.io — a great workflow engine. If not, please familiarize yourself with it and start using it. You will love it, and it will save you millions of dollars and many months of development time.
In short, Temporal.io allows us to write workflows in a programming language of our choice, Unit test them (!!!), and then run them in a distributed environment.
The platform is very stable, reliable, fast, and secure. Developers love it, but when it comes to ‘selling’ it to management and business people, it gets challenging because there is no visual representation of the workflow runtime state as a diagram. Business people love diagrams, and that allows con artists from low/no-code platforms to sell their snake oil (Appian, Jitterbit, etc.).
Well, we can do better, and this project demonstrates how temporal can be enhanced to provide a visual representation of workflows.
Note: Even though this project is written with Kotlin and runs on a JVM platform, the same approach can be used with any other language and platform supported by Temporal.
Worflows provide two query methods:
- One that returns workflow definition in PlantUML format
- Another that returns the name (or names) of current active states
A helper utility can be used to make those queries, enhance PlantUML definition with current state information, and create PlantUML server URL with encoded diagram. POC grade implementation can be found at this GitHub link.
I hope that the Temporal team will adopt this (or similar) approach and provide built-in support for workflow visualization from their UI. For now, we can implement this approach in our custom dashboard for workflows.
The demo project can be found on GitHub here.
- A computer with OS X or Linux (Windows can be used too if one likes pain )
- Java 21
- Maven (sdk install maven)
- Temporal CLI (brew install temporal)
- Python3 (brew install python3)
- Check out this project
- Check out the Visualizer project
Now, we are ready to experiment.
We can start by defining the workflow in planUML syntax and visualize it using the excellent IntelliJ plugin for PlantUML.
As we can see, the workflow is defined in a very abstract way, and we can have a good visualization of workflow.
To colorize the diagram, we simply need to add lines like ‘state #’ to the diagram definition. So, our helper script simply needs to prepend the closing tag with those lines. The workflow diagram will look like this:
The workflow is a Final State Machine (FSM), and we can define it by using a domain-specific language or a library. In this example, we use kstatemachine library.
Thanks to the kstatemachine library, our workflow definition is as readable as our abstract definition, but we benefit from the type safety and IDE support — the definition is in Kotlin language, and we can use all the power of Kotlin and IDE to simplify implementation.
Workflow Execution Demo
Run Temporal Server
In a separate terminal window, run Temporal Server:
cd <project-root>/temporal docker compose up
In another separate terminal window run our workflow and activities implementations
cd <project-root> mvn spring-boot:run
Execute Workflows and Visualize State
Open a separate terminal window at the project root
This will return a workflow ID, for example:
Running execution: WorkflowId a23da575-3ae3-43cf-bd0d-886470f34644 RunId 796b833d-3348-472d-93fe-0610668cac77 Type DataProcessingWF Namespace default TaskQueue data-processing-wf Args ["account42"]
Then, we make the workflow ID available for our helper scripts:
At this point, we can see the workflow state in the Temporal Web UI by opening this local host.
Opinions expressed by DZone contributors are their own.