Start tenanted process instance from non-tenanted definition

My application has an unknown number (potentially very large) of tenants, and I want to be able to run each process instance using a tenantId. However, I do not want to deploy each process for each and every tenant (seems illogical - the process definition should be shareable in my use case). How can I start a process from a process definition that has no tenant specified, but apply a tenant ID to the process instance? Is this even possible? When I try to start a process and provide a tenant ID, it seems to be trying to find a process definition that also has that tenant ID, which isn’t what I want. When I go hunting in the ProcessInstanceHelper, it looks like the process of creating a new instance just pulls the tenantId from the process definition. If the answer is that it can’t be done, it seems like my only options are:

  1. Deploy a tenanted version of each process definition on-demand (programmatically) as each tenant first tries to use it. Seems like performance (on first use) would suffer though, and I’d end up with a DB polluted with hundreds (or thousands) of deployments of each process, all of them identical except for the tenant ID. I think this would work, but it would be super ugly.
  2. Avoid the use of tenantId completely, and instead maintain some other variable (replicating tenant id) explicitly against the process instance and ensure that I always use that variable when querying for process instances. This seems error prone and presumably would cause problems with things like isolation of signals within the scope of a tenant.

Any good solutions to this problem much appreciated! Ideally I could somehow plug in to the instance creation process to provide my own tenant ID, regardless of what is on the process definition.


Another possibility could be to implement your own command to start the process instance and run it with org.flowable.engine.ManagementService#executeCommand(org.flowable.common.engine.impl.interceptor.Command<T>). The command can be similar to org.flowable.engine.impl.cmd.StartProcessInstanceCmd.


Thanks. This worked, although it ended up being a lot more code than it feels like it should have been. It would be great if there were something along similar lines to Camunda’s tenant ID provider SPI to make this more straightforward, as it seems like it must be a very common use case.