Variable scoping with service task

currently we are experimenting with Zeebe and the service worker task. we are consuming the tasks from a C# worker over the gRPC API. to make our worker predictable we would like to limit the variables available to the worker. so we tried some different things:

  • setting input/output variables. but looks like the concept is that those variables are in addition and not a way for explicit scoping.
  • use sub processes to move variables to different scopes. but this seems to have the same issue as even variables from a different subprocess are accessible in the worker.

also it looks like there is an API to specify the scope (SetVariable RPC) but that’s not likely something we would use for variables inside native zeebe workflows.

so the question is what’s the proper way to scope variables insde workflows?

Hi Daniel.

There are two different perspectives here: The scope of the variable and what a worker fetches.

As far as I understand, you want to limit the variables one worker fetches, which you can do by specifying the variables to fetch (gRPC: Zeebe API (gRPC) | Camunda Cloud DocsfetchVariable , also exposed in the C# Client: Zeebe C# Client: Zeebe.Client.Api.Worker.IJobWorkerBuilderStep3 Interface Reference)

Or do you care about the visibility of variables for a certain service task? Then this might work a little bit different than you expect: I/O adds variable to a scope, but every scope can also read variables from the outer one, see Variables | Camunda Cloud Docs.

Hope that helps?
Best
Bernd

thanks for the response!

if I get it correct, you can’t limit the variables available to a worker? the worker always gets all the variables and can only limit itself with specifying the explicit variables?

also every variable in every task is propagated to the root variable scope and is available to a worker?

is there a recommended way to manage the dependency on variables? as our workflow gets more complex the more variables we have in scope and it gets problematic to have the full picture of variables in use and wrongly depend on variables not expected to be used.

I have the same concern. Due to some obstacles of the micro services, I think it would be nice if the workflow engine could limit the variables specificly for particular step.

Best,