How to trigger the continuation of parent process instance when all child instances are completed

Hi Team,

We have a use case in our application where we need to process a customer order which is having multiple order items. for each order item, we need to execute a set of tasks in addition to some common tasks on the order level. to achieve this, we have designed the two bpmns. one is the parent which will perform order level tasks and the child bpmn will perform tasks related to each order item. depending on the no of order items in the order, we are creating that many parallel instances of child bpmn and passing the common parent business key to all child instances to keep the parent-
child relation ship.

To achieve the parallel multi instance behavior’s without any race conditions, we are using the multi-instance-with-delegate pattern described in this git hub project - camunda-7-code-examples/snippets/multi-instance-with-delegate at master · camunda-consulting/camunda-7-code-examples · GitHub

Now the problem is, after all the child instances are completed, we have some tasks left to perform on the parent instance. event though the parent instances is having a timer which periodically checks the child instance completion, we feel this solution will not fit if the child instances are long running. as the timer will poll indefinitely and will put more load on the job executor and to the database. to solve this problem, we have added a receive task on parent instance, which all child instances will try to signal upon their completion. but this can lead to another race condition when more than one child instances trying to correlate the message on parent.

Is there any other approach to solve this problem? please share your valuable inputs. attaching my bpmns for more clarity.

MiParent.bpmn (14.3 KB)
MiChild.bpmn (6.9 KB)

How many items per order do you have? Why don’t you use multi instance call activity? It would solve all synchronization problems.

@fml2 We have 1000+ items per order. we were using parallel multi instance activity before. but it caused lot of race condition and resulted in lot of optimistic locking exceptions. thus we switched to multi instance with delegate approach. also I heard from some articles that the multi instance activity is not suitable for creating large number of parallel instances.

If you ave that many instances and even problems with locking then I’d

  1. Consider sequential instead of parallel multiinstance
  2. Another design, i.e. not a process instance per item

Now a camunda team member will appear and say that you should consider camunda 8 with its unlimited scalability, but I won’t say that :slight_smile: