Two phase commit with Mongo

I am trying to sync workflow details in Mongo from Camunda upon every task execution and update Mongo with current list of Active tasks. While it works fine if both systems are up and running, the question I have is how do you handle scenario when Camunda was updated but Mongo update following Camunda failed because of which we may have a mismatch?
Is there a way to rollback latest commit or executed task in Camunda to reconcile with Mongo state? Or are there other strategies that I am probably not aware of?

I’m not familiar with Mongo, however I can comment on the general case where you want to write to multiple databases. In this case, you should use a two phase commit protocol that enables you to commit/rollback modifications to multiple databases in an atomic way. This will avoid inconsistencies.

I suggest you read up on XA transactions and mechanisms to achieve transaction integration in Camunda, i.e. have two applications share one transaction. Camunda itself has out of the box support for transaction integration with JTA or Spring-managed transactions.

Thanks for your reply. The challenge I have with using XA transactions is:
After completing camunda task, I need to read the state of workflow so reconcile tasks in mongo with camunda. Now inorder to do that without committing transactions is to “DIRTY READ” uncommitted data. So is it a good idea to use dirty reads?