How a Bank Uses Compensation Events in Camunda 8

Leveraging rollback with compensation events in case of errors for reliable, secure, and compliant financial transactions.
  • Blog
  • >
  • How a Bank Uses Compensation Events in Camunda 8

Constrained by rigid regulations and overloaded with high volumes of transactions requiring speedy processing, banks need to ensure the reliability and security of financial operations, whichever problems might come their way. While many things can go wrong in complex banking processes, the distributed architecture of modern Financial Institutions systems adds complexity to failure handling. We are going to explain how banks can efficiently automate transaction rollback across multiple microservices and provide a real-life example of Camunda 8 compensation events working in a bank.

What are compensation events?

One of the outstanding features provided by Camunda 8 is its ability to easily handle business transactions that went awry. This workflow pattern allows businesses to define compensatory actions and “undo” steps in a workflow if some operations in the sequence fail. In today’s complex business processes spanning across distributed architectures, we can find many examples where executed tasks need to be undone to reflect the real-world state.

For example, when a system runs financial transactions, money transfers, or online credit applications, it needs to confirm the request, process the transaction, and update the account. If any of the stages are not completed, the system has to be capable of rolling the previous steps back to avoid incorrect transactions or data inconsistencies. Namely, it would be inappropriate to leave the credit request in the confirmed state if the loaned money didn’t arrive in the client’s account, say, because of a failure of a microservice.

So, in business operations, Camunda’s compensation events enable the automatic reversal of actions that were successfully completed, but their results and side effects are no longer seen as desirable. Thus, the compensation feature ensures the process is preserved in a consistent state in case of errors, exceptions, and cancellations.

How do compensation events work in Camunda 8?

Saga

To enforce effective compensation, Camunda supports Saga, an interaction pattern that works well in data consistency management across complex microservice architectures. Unlike the two-phase commit protocol frequently used in distributed systems, the Saga pattern doesn’t reduce the overall system availability with transaction locks. It is also perfectly suited to modern NoSQL databases and message brokers that don’t support two-phase commit.

Thus, Saga is the preferable option for long-running business processes and highly distributed systems, which are almost universal in banking nowadays. It breaks complex processes into small, manageable steps, each of them accompanied by a compensation action needed for correct recovery in case of failure. As a result, the system remains fault-tolerant and consistent while retaining scalability and performance.

Zeebe and BPMN

Camunda’s Zeebe engine works as a Saga Coordinator responsible for either completing the overall transaction or aborting it, bringing the system into a known termination state. The engine has a log-based, event-driven design, where every state change is captured in an append-only log. This allows for efficient recovery and state management, which is crucial for implementing compensation events.

Compensation events in Camunda are created using the BPMN 2.0 standard in Camunda Modeler. They work closely with the engine, which handles process execution efficiently and can scale well.

When a process instance enters a compensation intermediate throw or end event, it triggers the compensation within its scope and invokes all compensation handlers of completed activities. The compensation handlers of active or terminated activities are not invoked. The compensation throw event remains active until all invoked compensation handlers are completed.

Specifics for the implementation of Camunda’s compensation events

  • Camunda makes it easy to model compensation in complex business processes with visual BPMN representations.
  • Users can create a compensation activity for every task in a process model, be it a service task, a human task, or a subprocess.
  • Camunda’s compensation can handle complicated situations like multiple instance activities, compensation handler interruption, triggering compensation handlers in a given order, and more.
  • Users don’t need to hand-code rollback logic across multiple microservices and can build robust error-handling mechanisms directly into their process models.

All in all, compensation flows built in Camunda save you the trouble of tracking each transaction individually and ease the complexity of rollbacks.

Real case of a compensation event for banking

Let’s look at how Camunda’s compensation works in a real-life banking scenario of transferring funds. As we’d like to focus on compensation events, we will slightly simplify the process by combining all client validations taking place before a fund transfer into one service task. The validation activities include:

  • Checking the format and correctness of the data entered, such as IBANs and bank details
  • Confirming that the specified amount does not exceed existing limits
  • Verifying the sufficiency of funds in the sender’s account
  • Identity verification
  • Anti-fraud, anti-money laundering, and compliance checks

The diagram below shows the following scenarios:

  1. If any problems are detected during the data validation, Camunda sends a notification informing the client about the fund transfer cancellation. The process is completed.
  2. If the validation is successful, the process goes on.
  3. In the next step, the sending bank writes off the specified amount from the client’s account. All the operations with the account are logged in the system.
  4. If something goes wrong during the write-off (the connection was broken, the bank did not send a response about debiting the account, etc.), Camunda informs the client that the fund transfer process ends in an error. The process is completed.
  5. If the write-off operation is successful, the process continues.
  6. The next step is replenishing the receiver’s account with the specified amount.
  7. If the system identifies an error boundary event during the execution of this operation, Camunda informs the client and triggers a compensation event—a rollback of writing off the funds from the client’s account. Then, the process is completed.
  8. If the crediting causes no errors, Camunda logs the account replenishment operation and notifies the recipient of the funds added to their balance. The process is completed.
Compensation-events-bpmn-camunda

By implementing the compensation event, the bank ensures no funds are lost or incorrectly processed, maintaining data consistency and complying with regulatory requirements.

Compensation events: use cases and benefits for banking

Compensation events aren’t limited to simple debit-credit operations. They can be used across a wide range of banking processes:

  • Loan application processing. An approved loan can be rolled back automatically when a post-approval check fails.
  • Fraud detection. It is possible to reverse a flagged fraudulent transaction and notify the relevant departments in the process.
  • Cross-border payments. In case of exchange rate mismatches or compliance violations, multiple currency conversions and international transfer operations can be efficiently handled with compensatory actions.
  • Lending and mortgage transactions. If the credited party changes their mind or calculation errors are detected, it will be appropriate to change the agreement terms or roll the whole process back with compensation events.
  • Commission and fee calculation. When a customer is mistakenly charged a commission or fee, a refund is a surefire way of correcting the situation.
  • Settlements and clearing operations. In the event of failures in clearing processes (for example, in interbank transfers), compensation events can roll back and re-execute transactions or ensure the funds’ reversal.
  • Payment systems and acquiring. When a payment system fails to process a payment, it can use compensation events to cancel the transaction and return the funds to the customer.
  • Card transactions. Returning funds or cancelling the transaction will also be helpful in case of an erroneous debiting, for example, because of duplicate transactions.
  • Currency transactions. If there is a change in the exchange rate during the conversion process, compensation events may adjust the original transaction or return funds with due regard to the new conditions.
  • Deposit transactions. If a client terminates a deposit agreement early or there are errors in interest calculations, compensation events may adjust the maths or roll back the transactions.

By adopting automated compensation and letting Camunda coordinate complex banking processes, financial institutions can reap many benefits:

  1. Minimise financial risk. By defining compensation flows, banks can reduce the risk of incomplete or erroneous transactions, ensuring that funds are accurately handled.
  2. Ensure compliance. Automated rollbacks help prevent unauthorised or incomplete transactions and thus work toward meeting regulatory requirements like the PCI DSS and GDPR.
  3. Reduce manual workload. Compensation events allow banks to eliminate manual intervention in case of transaction failures, freeing up valuable human resources for more high-value tasks.
  4. Enhance customer trust. Banks can build greater customer trust by implementing accurate and transparent transaction processing.

Using compensation events beyond banking 
As event-based, distributed architectures are frequently found outside the financial industry, Camunda’s compensation solution has a much broader application area. Here are some examples of the compensation events usage in other industries:

  • Supply chain management: Prevent stock discrepancies by reversing inventory changes if a shipment fails.
  • Healthcare: Handle errors in patient data processing or treatment scheduling when managing clinical trials.
  • E-commerce: Automatically cancel order confirmations and refund payments in case of errors in order processing or payment authorisation.
  • Insurance: Ensure accurate financial records by cancelling overpayments or rectifying policy processing errors.

Final thoughts

By leveraging compensation events, organisations can build more resilient and adaptable process automation frameworks. Thanks to the faster recovery from failures and the reduced risk of process downtime ensured by automated compensation, businesses become more agile and competitive. Camunda 8 provides a powerful mechanism for banks to handle the complexity of modern financial transactions with confidence. By automating rollback actions, they can meet regulatory requirements and enhance operational efficiency while offering a more secure and reliable banking experience for their customers. Contact Camunda or a certified Camunda partner to get professional help in designing your compensation events.

Editor’s Note: This post was written by Maria Alish, a Camunda Champion. Would you like to become a Camunda Champion, and potentially have your blog post published here as well? Learn more about our Champion Program and how you can apply.

Start the discussion at forum.camunda.io

Try All Features of Camunda

Related Content

Camunda enables effective AI governance by acting as an operational backbone, so you can integrate, orchestrate and monitor AI usage in your processes.
Learn how NatWest used Camunda to put AI into action to help them improve customer experiences, increase employee productivity and detect fraud faster.
See how you can solve the RPA Challenge (and much more when it comes to orchestrating your RPA bots) with Camunda.