Workflow ID policy suggestion

Hi, at my company we plan to use temporal to handle customer order workflows. We are not confident on how to choose a good workflow ID and reuse policy, perhaps someone had a similar experience and a good solution for it.

We have a couple of workflows related to the order, to make it simple, lets take two of them

  • ActivateOrder
  • TerminateOrder

Our idea is to give our workflows the ID of the order (as suggested in the docs)

We don’t want TerminateOrder and ActivateOrder to run at the same time, so we wan’t to reject workflows with the same ID. However, if for example TerminateOrder fails, we want to be able to re-run the workflow with the same ID, so WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
seemed like a good policy. But then we realised that we do want to allow a TerminateOrder after a successful ActivateOrder has completed. This will not work, with the current policy.

This then led to us thinking about workflow IDs like TerminateOrder-{WorkflowID} but seems like an ugly solution.

I think the policy we want is to reject workflows with the same ID only if a workflow with the same ID is already running

perhaps this one ?

Greatly appreciate any help with this, love temporal !

1 Like

The WORKFLOW_ID_REUSE_POLICY applies only to closed workflows. Under no situation multiple open workflows with the same ID are permitted. So in your case I would use ALLOW_DUPLICATE to be able to execute workflow after previous one completed.

Another design option is to have a single workflow that performs both operations and signal it (possibly using signalWithStart). This way the workflow is going to have full control over ordering of operations.

1 Like

To get a better understanding what you mean, Do you have a sample of this design?

We have samples of each piece of the design, but not end to end.

Money batch sample demonstrates how to aggregate data across multiple signals. It also demonstrates signal with start.

As workflow receives all the signals it can perform any type of logic based on the signals received.