Embedding Camunda into another platform - how to sync db txn

When embedding Camunda into another java platform - how to sync db txn
I am thinking of invoking function of another platform from inside each java delegates of Camunda. But as both products use separate db connection pools what can be done for syncing their transaction at any task. E.g. when camunda commits in db but the other platform rolls back. Or vice versa.
It would be a tedious work if we have to write compensation code of ‘logical rollback’ for each action in the other platform.
I am not aware if Camunda has a way to ‘undo’ or ‘rollback’ that can be invoked if the other platform throws error.
Any tips/pointers is appreciated.

Hi,

The keyword you are looking for is XA transactions. I recommend to read up on this step-by-step, i.e. first begin with a little bit of theory, then understand how XA transaction can be used in non-Camunda Java applications (e.g. in plain Spring or Java EE applications; also depends on the application server you use), then try to integrate it with Camunda.

For the Camunda part, the essential parts to for integration with Spring- or JTA-managed transactions is documented at the following locations:

Hope that helps a bit.

Cheers,
Thorben

Hi Thorben,
The other platform is not open or configurable by us. I might not be allowed to customize it to change to XA driver at this time. So am not sure of being able to use XA yet.
Is it possible that we use the below workaround:

  • in each delegate call we attempt to commit the platform transaction
  • if the commit succeeds then Start a new transaction of platform and exit the delegate like normal
  • if the commit fails then I want to mark the current task as ‘Errored’ or Retryable in Camunda. And I am not sure how to do so.

I have the gut feeling that it is not a good idea, but I find this matter too complex to give a proper answer. It may work fine in your usage scenarios. However, keep in mind that the devil is in the details with these things. For example, what do you do when the platform transaction commits successfully, but the process engine transaction is rolled back?

Interrupting execution is done in Camunda by raising exceptions. The process engine transaction is then rolled back to the last wait state (e.g. asynchronous continuation). In case of asynchronous continuation, the job executor will perform retries.

Thanks Thorben.
About your comment: what do you do when the platform transaction commits successfully, but the process engine transaction is rolled back

Is it possible that I attach a flag (or custom attribute) to such tasks?
The purpose of this flag would be that if the platform txn does not need to be rerun and all i want from retry is to complete the task in Camunda database, I can insert a check in each delegate to look at this flag and skip platform call during retry.

Perhaps the Saga pattern as written by Bernd could help here…

regards

Rob

Saga pattern would be needed if my application had more than one subsystems (which render business functionality). It only has 1 platform which is aided by 1 bpmn engine (a technical component). So just for technical components is it still required for platform to code the saga?
I am not aware of the complexities but if we had a way to tag those task instance where platform succeed but BPM engine failed, then i can use that tag to avoid rerun of platform during any retry. I am not aware if ServiceTask class has such a way.
I need help on that.
Let me know if there is another way out of this issue of ‘consistency’ (example some eventual consistency too should be ok)?.

Hi,

I guess my reference to the Saga pattern was more a reference to managing distributed transactions. In this case you do have two independent transaction systems. The concepts of idempotency, query and compensation may assist in your realisation…

regards

Rob

I believe saga pattern means i will need to write a bunch of undo flows. Even though I am using one system with an embedded bpm. It would make the app more bulky. Hoping to see a more manageable solution. I have already written a simple workflow in same platform and that works great except that it does not have a cool modeler to edit the workflow. So am looking to use Camunda. So hoping it does not force a lot of redesign. .