Rollback Database Transaction

  • Rest End point is called .We start the workflow using runtime.startbykey
  • Then order is saved in DB.If some issue occurs we thrown an exception which is returned as response to the client.Order is not saved.
  • If Order was saved in DB in step 2 ,then we call send order.If any issue occurs in this step(Send Order)
  • then we thrown an exception which is returned as response to the client by Rest end point.

My question is how do i rollback Step 2 in case my Step 3 fails

You don’t have to rollback the step 2. Apparently, you don’t have any async points in the process model (otherwise you wouldn’t be able to send responses to the REST call). Hence the whole process is executed in one transaction. And on the thread serving the REST request.

1 Like

@fml2 so you mean my process model is just fine then.I suppose

If the DB you save the order to is another one than the one used by Camunda, and you don’t have a distributed tx manager, the order will be committed, you can’t do a rollback then.

1 Like

@fml2 Database is different than Camunda.(Oracle) .How can i rollback in this case?

Use a tx manager capable of two phase commit. The tx manager should control both the camunda and the oracle DB.

@fml2 does camunda has any example anywhere ?in GIT.I coudnt find

Hi @my_camunda_profie_1,

it sounds like you have to handle distributed transactions. BPMN 2.0 supports them with Compensations. You write an explicit task to delete the data from the Oracle DB and invoke it as a compensation task.

You can find the technical details here: Cancel and Compensation Events | docs.camunda.org

Hope this helps, Ingo

1 Like

@Ingo_Richtsmeier, would this also work if the process has no async points at all? If I understood the OP correctly, the process does not have them because it sends a synchronous reply to a REST request after the third activity has been executed.

@fml2 I want to send synchronous Response to REST .Can you help how to acheive it.Response can come from any other Workflow.

Halt the workflow and return the response to Controller - Camunda Platform 7 Topics / Camunda Platform 7 Process Engine - Camunda Platform Forum

Hi @fml2,

generally, yes. It depends on the rollback operation, if you want to delete a dataset that is not yet committed to your business database you will get an issue there. If you invoke two synchronous rest calls to add and remove a dataset, all is fine.

The compensation will be invoked in the same thread of the engine if no asynchronous continuation is set.

Hope this helps, Ingo

So there are two ways to have the consistency:

  • a purely technical way (ACID transaction, requires a distributed tx manager)
  • eventual consistency, via compensation events