Write a single workflow with multiple languages

is it possible that a single workflow can be written by different languages?
For example I’d like to implement a workflow that have two activities for some reason I need to write the first activity in java with java sdk and the second activity needs to be written by Golang with Go sdk. how can I combine these two activities into a workflow, is this doable directly or indirectly?

This is fully supported. Make sure that activity workers in different languages are using different task queue names and workflow specifies correct task queue names when invoking these activities.

1 Like

thanks very much, will try this out

Are there any gotcha-s related to parameters serialization?

Any way to define activity/WF interfaces in gRPC? Just curious

By default JSON serialization is used. So if both languages use structures that are compatible with the generated JSON you should be fine. You can also use protos as their serialization is also supported.

I’m also looking into using mix activities (written in different languages) however I can’t understand how to address “language A activity” from within the “language B workflow” (how can I create the stub if the interface class is in another language ?)

Here are some examples that show off interaction of client and workflows/activities using different Temporal SDKs:

  1. GitHub - temporalio/temporal-pendulum: Demo showing off Temporal Polyglot features (Java, Go, PHP) - shows how a client can use a typed approach to invoke workflows that are written in different languages supported by Temporal currently.
    The main application is written in Java, and can invoke workflows written in Go, PHP, and TypeScript.
    You can always use the “untyped” approach, meaning create an untyped stub where you invoke a workflow execution by its type name (string). The typed approach shows that you can
    write an interface in Java, and as long as it has the same workflow type, and matches the workflow, signal and query method names you can use that interface to create a typed stub.
    See for example:
    temporal-pendulum/PositionWorkflow.java at main · temporalio/temporal-pendulum · GitHub
    which is used by the game client start, signal, and query:
    temporal-pendulum/workflow.go at main · temporalio/temporal-pendulum · GitHub
    temporal-pendulum/workflows.ts at main · temporalio/temporal-pendulum · GitHub
    and
    temporal-pendulum/PositionWorkflow.php at main · temporalio/temporal-pendulum · GitHub

  2. GitHub - temporalio/temporal-polyglot - Temporal Polyglot sample that shows more of what I think you are asking here. It shows for example how you can use ExternalWorkflowStub to invoke a Go activity from a Java workflow: temporal-polyglot/SimpleWorkflowImpl.java at main · temporalio/temporal-polyglot · GitHub
    as well as how to call a Java Activity from a Go Workflow: temporal-polyglot/workflow.go at main · temporalio/temporal-polyglot · GitHub
    Note that in the Java workflow->Go activity (and vice versa) in this sample uses the untyped approach but you can also use the typed approach as well in this case as shown in the first example.

As far as data inputs go, as @maxim mentioned, Temporal uses JSON serialization by default. This allows you to do things like invoke a Go activity from Java workflow, and have a data model, for example: temporal-pendulum/GameInfo.java at main · temporalio/temporal-pendulum · GitHub
to pass it as argument to a workflow or activity and have temporal deserialize the JSON to a struct in Go for example: temporal-pendulum/workflow.go at main · temporalio/temporal-pendulum · GitHub

  1. GitHub - tsurdilo/temporal-java-workshop: Introduction to writing Java applications using Temporal SDK (and Temporal Server) - in our recent Java SDK Workshop we showed a demo where we stared a PHP workflow, and then stop the worker in the middle of its execution, and then continue and complete it by a Java workflow. You can see the demo here: Temporal Workshops: Java SDK Intro - YouTube

Hope this helps.

3 Likes