Translate JSON workflow

What is the preferred way to translate JSON workflow definitions(created by a web app) as a Temporal workflow? In all the examples given, the workflow logic is wired within Java code.

1 Like

The gist of the idea is that you write an interpreter workflow for your JSON definitions.

There are multiple ways to structure such a workflow. Here is the approach that we recommend:

  1. Implement an activity that accepts your DSL workflow ID and the current state of the workflow. And returns the new state which includes the list of operations (like activity invocations or timers) to execute.
  2. When requested, the activity loads (or gets from a cache) the specific object graph generated from JSON by its ID and applies the current state to it to get the new state.
  3. A workflow is implemented as a loop that invokes that interpreter activity to get the updated state with operations to execute.
  4. The requested operations are executed. For example, activities are invoked or timers are created.
  5. Upon completion of any of the operations, the state is updated and the interpreter activity is invoked again.

We have plans to write a sample to demonstrate this approach.

I have not completely understood the approach, an example would help.

As I understand, when writing a java workflow, the developer does not worry about managing state himself. Isn’t managing states different from that?

  • Is it possible to have a builder API part of Temporal SDK that could compose a dynamic workflow?
  • What are your thoughts on dynamic code generation? I know its not straightforward to load the compiled classes in Java, may be using a byte-code generation library?

As I understand, when writing a java workflow, the developer does not worry about managing state himself. Isn’t managing states different from that?

Developer has to manage state in the form of variables of the program he is writing. The Temporal takes care of preserving the state of variables and threads. So the state of the dynamic workflow execution has to be managed by your code.

  • Is it possible to have a builder API part of Temporal SDK that could compose a dynamic workflow?

We have plans to add DSL SDK for simplifying the creation of your own dynamic workflows. But at this point, you have to write it yourself.

  • What are your thoughts on dynamic code generation? I know it’s not straightforward to load the compiled classes in Java, maybe using a byte-code generation library?

I’m not sure about the value of this. Writing a JSON interpreter is 100 times simpler IMHO.

1 Like