compensating service transactions

22
Compensating Service Transactions SOA Patterns Webinar Series 09/30/2014 Nuwan Bandara, Senior Lead Engineer Nipun Suwandaratna, Senior Engineer

Upload: wso2

Post on 28-Nov-2014

254 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Compensating Service Transactions

Compensating Service Transactions

SOA Patterns Webinar Series

09/30/2014

Nuwan Bandara, Senior Lead Engineer

Nipun Suwandaratna, Senior Engineer

Page 2: Compensating Service Transactions

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

Page 3: Compensating Service Transactions

TransactionsWhat are Transactions ?

An action or a series of coordinated actions performed to fulfil a business functionality (business Transaction)

Service C

Service B

Service D

Service A

Page 4: Compensating Service Transactions

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

Page 5: Compensating Service Transactions

Error Situation

What if something Goes Wrong ?

Can we always Rollback the Process?

Page 6: Compensating Service Transactions

Rollback situation

๏Item purchase over an ecommerce site

Page 7: Compensating Service Transactions

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

Page 8: Compensating Service Transactions

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

Page 9: Compensating Service Transactions

Long Running Process Example

Travel Booking Service Scenario

Book Hotel

Book Air Ticket

Book Taxi

Travel Booking Service

Page 10: Compensating Service Transactions

Travel Booking Service - Sequence

Page 11: Compensating Service Transactions

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.

Page 12: Compensating Service Transactions

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

*

Page 13: Compensating Service Transactions

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

Page 14: Compensating Service Transactions

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

*

Page 15: Compensating Service Transactions

Undo Operations in the Travel Booking System

Hotel Booking Service

-Book Hotel Room-Cancel Booking

Travel Booking Service

Airline Booking Service

-Book Ticket-Cancel Booking

Taxi Booking Service

-Book Taxi-Cancel Booking

Page 16: Compensating Service Transactions

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

Page 17: Compensating Service Transactions

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

Page 18: Compensating Service Transactions

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

Page 19: Compensating Service Transactions

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

Page 20: Compensating Service Transactions

Compensation with BPEL

o Driven by partner links

o Each invocation has a compensation

Page 21: Compensating Service Transactions

TCC With WSO2 ESB

Page 22: Compensating Service Transactions

Thank You !!