Execution details of delegations to business code

I am interested to understand more details of how delegation to business code is handled, for the architectural pattern of using Camunda as embedded library.

I am assuming the thread of executing process tasks will be the one that is initiating the process instance. Until what point is that true ? When a decoupling from the main thread is done ? And if this is true, how is the threading handled then ?

Also I am curious if the java delegates can be used to comply with reactive semantics, for example using Spring Webflux Reactor.

I saw there is an implementation of Camunda event bus, but for me it is not clear how end to end backpressure is respected. I am guessing the event bus is single threaded, thus the only backpressure mechanism is carried out by the fact that the thread is blocked. But in the Delegate method, executing the business code, if you start a reactive stream, the only way to execute it is by subscribing in the method and again blocking the thread. Is there a way in which you can truly code the delegates in a reactive manner ?

The tread will keep running until the engine reaches a transaction boundary. This this includes running the delegate code. You can read more about how transaction work here:

1 Like

I’m not sure if I understood completely. But in a process, when a boundary is encountered, the work is resumed at some point using the JobExecutor. And that has it’s own thread pool ?

Yes, exactly right :slight_smile:

Oke, thanks ! And can you also provide me with some input, regarding the second part of my question, regarding reactive programming strategies and the bus module ?

Generally speaking if you want to start to connecting with other distributed system as part of a micro service architecture, it’s not always the best idea to delegate code. The external task pattern is better suited for connecting those kinds of system together.

I was thinking so, regarding the external tasks, but I read on some user stating there are some performance limitations in using external tasks. On the other hand I don’t know how external tasks will work using the embedded way, but I am assuming there will still be fetchAndLock calls to DB. But that indeed can be of some aid for reactive part since you can model the flow to pull the tasks based on the reactive stream availability. But if you have some info regarding possible performance limitations that would be great since I can asses their usefulnes for my use cases.

Can you use external tasks pattern with embedded engine ? In this way how the execution is delegated ? through the network interface or the Java API ?

Your best bet would be to add the Camunda REST API and have the external task communicate to the engine that way.

But there is also Java API for external tasks, but in that case it would be much of an external task.