What is the best way to start a child workflow (with a specific workflowID) if it doesn't already exist as one atomic operation?

I’m trying to create a setup where several workflow instances rely on the results of the same child workflow (with a specific workflowID). Currently, if all the parent workflows attempt to execute the child workflow simultaneously only one of them is able to read the results and the rest get a ChildWorkflowExecutionError that says “workflow already started”. Is there any way to replicate what workflow.ExecuteWorkflow does where if the workflow is already running or exists, it just returns the result of the existing workflow?

Unfortunately, it is not yet supported directly. Here is the issue to get such a feature added.

The workaround is on “workflow already started” to execute an activity that the result of a workflow using WorkflowClient.

Appreciate the prompt response as always. I was thinking about falling back to the solution you suggested, but I wasn’t sure if it would violate correctness. Great to know that it is indeed a valid workaround. Thanks!

Calling WorkflowClient from workflow directly will violate correctness. Calling it as any other API from an activity is always OK.

1 Like