Seems like you have two new processes started with different process-instance ids for same requests.
Associating a unique ProcessInstanceBusinessKey for each request when starting the process instances.
RuntimeService runtimeService = ..;
String orderId = ..;
ProcessInstance shipmentInstance = runtimeService
.createProcessInstanceQuery()
.processInstanceBusinessKey(orderId)
.singleResult();
Refer the use cases for businesskeys: How to Use Business Keys? | Camunda
And the below post:
It can be solved by below approaches:
-
By enabling uniqueness of the businessKey field in camunda tables for business-key configuration
-
Configure a ExecutionListener in StartEvent of the process and query by the businessKey in runtime tables and if process already exists throw the exception if already same entity is in process.
long processCount = execution.getProcessEngineServices().getRuntimeService() .createExecutionQuery().processDefinitionKey("aProcessDefinitionKey") .tenantIdIn("aTenantId").processInstanceBusinessKey("aBusinessKey") .active().count(); if (processCount > 0) { throw new RuntimeException("Process already exists for businessKey: " + execution.getBusinessKey()); }