Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Compensating Service Transactions


Published on

Published in: Technology

Compensating Service Transactions

  1. 1. Compensating Service Transactions SOA Patterns Webinar Series 09/30/2014 Nuwan Bandara, Senior Lead Engineer Nipun Suwandaratna, Senior Engineer
  2. 2. Agenda o Transactions - basic overview o Rollback Mechanism o Long Running Processes o What is Compensation o Compensations methods o Try-Confirm Cancel (TCC) Model o Compensations with BPEL o TCC with WSO2 ESB o Demo
  3. 3. Transactions What are Transactions ? An action or a series of coordinated actions performed to fulfil a business functionality (business Transaction) Service B Service C Service D Service A
  4. 4. Stateful and Stateless Transactions and processes o Stateless transactions do not track or maintain a record of the occurred events o Stateful transactions keep track of the current state of the interaction. This information could be in memory or persisted to a storage such as DB or File o A Process could be either short transient or long running, and made up of a collection of stateful and/or stateless transactions
  5. 5. Error Situation What if something Goes Wrong ? Can we always Rollback the Process?
  6. 6. Rollback situation ๏Item purchase over an ecommerce site
  7. 7. Rollback Mechanism o Services are atomic units that provide a clearly defined business functionality – A service is responsible for handling errors when it is invoked. But it’s not the job of a service to make sure the integrity of the overall process (that would make the system tightly coupled) o When services are grouped to form a process (composite service) the Transaction Coordinator has to handle the undo operations when errors occur. o ACID transactions ensure integrity. o Not practical in Long Running Processes since resources are blocked for a long time o More memory/resource consuming since all services need to preserve their original states till a commit or rollback is notified
  8. 8. Long Running Processes o Services are atomic units that provide a clearly defined business functionality – A service is responsible for handling errors when it is invoked. But it’s not the job of a service to make sure the integrity of the overall process (that would make the system tightly coupled) o A process that is suspended upon external input o Inputs could be triggered by some event or by human interaction o May be made up of a series of transactions
  9. 9. Long Running Process Example Travel Booking Service Scenario Book Hotel Book Air Ticket Book Taxi Travel Booking Service
  10. 10. Travel Booking Service - Sequence
  11. 11. What is Compensation Compensation is the process of restoring a system to it’s original state upon the occurrence of an error or a situation where the business transaction could not successfully proceed any further.
  12. 12. When is Compensation Needed o In situations where multiple services that are not make up a single transaction and the business process as a whole is not ACID o That is, a rollback of the current transaction/service does not help to restore the integrity of the overall business transaction. o In Long-Running processes *
  13. 13. Compensation as a regular Transaction o This is when the compensation is performed as a regular transaction E.g: In a stock trading scenario If a stock broker buys 5000 stocks of company A for the price of $2.00 each by mistake the only way to compensate for it is to sell the same for $2.00 each (or more) But stock prices cannot be guaranteed
  14. 14. Using Undo Operations o Each service should provide a fault operation o Synchronous services – No issues, service returns fault o Asynchronous – Mechanism should be in place for the caller to wait for the response from the service *
  15. 15. Undo Operations in the Travel Booking System Taxi Booking Service -Book Taxi -Cancel Booking Hotel Booking Service -Book Hotel Room -Cancel Booking Travel Booking Service Airline Booking Service -Book Ticket -Cancel Booking
  16. 16. Cons of Undo Operations o Air Line is at a risk of loss if the reservation is cancelled o Hotel is at a risk of loss if booking is cancelled o Taxi service is at a loss if the taxi booking is cancelled o Customer or Travel Agent is at a risk of loss if any of the above systems denies cancellation or does not refund full amount o Someone is at the risk of losing money if the resources that are reserved are revenue generating resources
  17. 17. The TRY-CONFIRM/CANCEL Model o TRY Operation – Reserves Airline Seat, but the booking is not complete o CONFIRM – Confirms the bookings if all other requirements are fulfilled o IF other requirements are not fulfilled send a CANCEL request
  18. 18. Characteristics of the TRY-CONFIRM/CANCEL Model o Each request remains tentative until it’s Confirmed or Cancelled o Cancellation timeouts will be set by service provider o Aggregates XA based (2PC) and Compensating transaction models o Uses a coordinating service o Uses Http Verbs (POST, PUT) to carry out the transaction
  19. 19. Advantages of the TRY-CONFIRM/CANCEL Model o Leads to a loosely coupled transaction model o Eliminates the need to have a compensating service for all the forward actions o Decouples Error handling o Increases Autonomy
  20. 20. Compensation with BPEL o Driven by partner links o Each invocation has a compensation
  21. 21. TCC With WSO2 ESB
  22. 22. Thank You !!