How to handle Camunda database Transaction rollback

We are using Camunda as our bpm engine and we integrate with it trough TaskListener events.
So when we receive an event that a new task was created in camunda then we create it in our system as well.
Recently we faced the following issue:
We receive the event that a task has been created in camunda, so we create it as well in our system, then when the transaction is commited in camunda and one of the sql query fails the entire transaction is rolled back. Next when the job is being retried the same mechanism happens and we receive again the event that a new task is created so we create it in our database as well. In the end we end-up with multiple tasks which do not exists in camunda.
Another issue is when we receive an OptimistickLockException and we end up with creating a task in our system multiple times, every time the job is retried.
How can make sure we create a task only when it was successfully created in camunda?

Hi @nmatei
You can make sure that you do not roll back over a listener if you use the asynchronous before/after tickbox on your tasks - this would then ensure the transaction is commited to the Camunda DB.

Thank you for quick reply @Niall. The problem is the bpm process can be designed by an end user, so they might not tick the before/after checkboxes.
Would you recommend we do this programmatically by extending AbstractBpmnParseListener and in parseUserTask set asyncBefore/asyncAfter to true? If we do this what would be the downside?
Thank you,
Narcis