Camunda concurring processes with shared resources design

Let me provide you a more detailed explanation
There is a process definition , let’s call it process definition 1, which contains some business flow between buyer end seller , and by the end of that flow, an apple will be sold to buyer. Now in case if have 2 instances actively running to sell apple1(process instance 1 and process instance 2), and 3 process instances to sell apple2(process instance 3,4,5), if let’s say process instance 2 reaches the sale, process instance 1 has to be terminated. Same goes for process instances to sell apple2, if one of them reaches the sale , the other two must be terminated.

Rough thoughts:

You could wrap the tasks In a sub process and after each task (or whenever you feel it should be done) you check if the product has been sold/no longer available. And if it is no longer available you throw a BPMN error and catch it to process it. Something like: https://docs.camunda.org/manual/7.8/reference/bpmn20/events/error-events/#error-boundary-event

You could also look at using compensation events and tasks as there might be the need to roll back previous applied changes?

Are you trying to build a purchase flow / checkout flow?

Error handling will not cut it, because it will require you reaching resource allocation stage in order to find out that resource is no longer for sale, I’m trying to build sale negotiation flow, where seller might have multiple parallel negotiation instances but whichever flow reaches agreement first gets the resource and all other negotiations should be cancelled since there is nothing to negotiate for.

How about something like this then:

Thank you for suggestion, but I was considering pool with two lanes, for seller and buyer (should I switch to to two pools instead ?), can I still make boundary catch message event for entire pool? And how do I proceed to termination of the entire pool after receiving the message ?

Lanes are purely a Annotation/visual. They do not have any execution function in the engine.

What is the value you see in having two pools (which would mean two processes definitions)?

And how do I proceed to termination of the entire pool after receiving the message ?

Take a look at the docs on Sub-Processes and Message Boundary Events up on how Interrupting Message Events work. When the message is executed, the inner pool will not continue, and when the parent pool reaches the end event it will stop the process. THe Termination event is only used as a example of a “hard stop”, but in my scenario above a non end event would work as well.

I was considering two pools based on the example of two approval process except that buyer end seller are now negotiating with each other, constantly sending messages back and forth. After each party would receive certain message they would react upon then until one of the following week happen , either both would agree/ disagree and process will end or process will need to be terminated since other concurrent negotiation reached agreement for the same resource. I am having a hard time sorting out how to build this kind of interaction between two parties using subprocess and I would be very grateful if you would help me, thank you.

Is this a fixed list of steps they negotiate?

can you provide a flow diagram just written in Visio / not a BPMN, just a visual picture of how you envision it working

Here is a “endless” scenario (S2):

Edit: Updated with Better Version:

@daniyar updated above with better version

Stephan, thank you so much, I did not expect to have so many inputs from my first pits on form :slight_smile: , right now it is 11 pm my region, and I cannot reach my PC, I will attach flow the rest thing tomorrow morning, however I can tell you flow seems to be fairly straightforward, buyer initiates flow buy filling out order request, afterwards seller has to review it, having 3 options , decline end the process ends, agree, end the process ends, end negotiation, if he chooses to negotiate, he has to provide negotiable item. After providing the negotiable item , the order is now moved back to buyer to review it, having same 3 options and so on.

@StephenOTT attaching abstract sample bpmn that i was hoping to use

Okay so what’s wrong if you build that flow? Looks reasonable.

in my flow, im not really sure how to send signal or message to terminate concurring flows after reaching the end, when in your diagram it is pretty straight forward, since the flow is encapsulated in subprocesss with boundary catch event to interrupt it.

There are no signals or messages in your design. And you have no parallel flows

considering that you might have multiple process instances, and only one item to sell, as soon as one of them to reach the end,it will have resource consumed, while other process instances will be continuing the negotiation for the sold item, and i want to interrupt that, but i dont know how.

Take a look at: Support for Script Implementation on Messages Events.

Add your message to the places where a purchase occurred and develop a strategy for how you will know which process instances are all for the same product. (Like having a product id that you store as a process variable )

thank you for the suggestion, but i have difficulty of understanding where exactly to catch the message event, and how to terminate the process ? should i be catching event on both lanes or only once? After catching event if i proceed to termination event, will it terminate the hole pool? or only the lane ?

Drop the lanes and add your process into a sub process like my previous example

1 Like