Help me understand the scope of workflow data

I’m trying to use (abuse?) Temporal’s event sourcing to create a simple approval workflow. Here is how I thought it would work…

  • Submit workflow input
  • Wait for approval signal
  • On approval signal, start “ProcessApproval” activity that does validation and appends approver to list on original input object
  • Complete workflow when approvers > required approval count

The issue I’m running into is that the approvers list ends up accumulating and is visible across all workflow runs. I’m not sure exactly why this is happening as I thought each workflow execution would be independent.

Is this type of state expected to be tracked via an external system or is there some way I can keep Temporal as the only dependency for this flow?

Some questions.

  1. What do you mean by “submit workflow input”?
  2. What do you mean by “Process Approval” activity “append to list on original input object”? Activities cannot mutate workflow data. They only can return results.

I believe I found the issue. I am using a struct for my workflow. I had an Execute method, handlers and the workflow data all contained within the struct. I expected that the struct instance was unique per workflow execution, but that does not appear to be the case. Removing the workflow data from the struct to a local var within my execute method appears to correct the issue of data being shared between workflow executions. However, it also requires me to inline my handler funcs instead of using the struct methods to allow for access to the var defined in my Execute method.

Edit: I’m using Go.

Is there some better way to use structs for workflows and have a per execution state managed at the workflow layer?

Instantiate the struct at the beginning of the workflow method. And then invoke a method on it.