SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Compensating Transactions:
When ACID is Too Much
Dr Paul Robinson
paul.robinson@redhat.com
@pfrobinson
Agenda
•  Background
•  Non-transactional resources
•  Cross-domain distributed transactions
•  Long-lived transactions
•  What we have today & planned
•  Getting started
ACID Transactions
Positives
•  Strong guarantees
•  Tolerate (certain) failures
•  Easy API to develop against
Negatives
•  Blocking
•  Can reduce throughput
•  Requires two-phase aware resources
•  Tight-coupling
ACID transactions
not suitable?
Don’t give up on transactions
altogether!
Extended Transactions
•  Umbrella term
•  Alternative to ACID
•  Relaxes some ACID properties
Guarantees
None ACIDExtended
Compensation-based
Transactions
•  Based on Sagas
•  Academic research from 1987
•  ACID vs Compensation-based transactions
•  ACID
•  Phase <=1: acquire locks & log
•  Phase 2: commit/rollback changes
•  Compensation-based
•  Phase <=1: commit changes & log
•  Phase 2: confirm? / compensate change
Hang on….
What effect does this have on
Isolation and Consistency?
Looks a bit dubious to me!
Isolation: ACID
Isolation: Compensations
Previous Support in Narayana
•  WS-BusinessActivity
•  Oasis Web Services standard
•  Standardizes
•  Message format
•  State machine
•  No API
•  Problems?
•  Web services only
•  Low-level API
Compensations API
•  JTA-like API
•  Application API only
•  Maybe AS and RM in future
•  Interop with JTA 1.2
•  Transport Neutral
Onto the examples…
Non-Transactional Resources
•  Transactional Resources
•  Participate in a two-phase protocol
•  Prepare and later commit/rollback
•  Non-transactional resources
•  Can’t participate in a two-phase protocol
Compensation-based transaction is an option
Code Example
•  Ecommerce site, selling books
•  Coordinates:
•  Updating databases
•  Dispatching package
Service
public class BookService {
 
    @Inject
    PackageDispatcher packageDispatcher ;
 
    @Compensatable
    public void buyBook(String item, String address) {
 
        packageDispatcher.dispatch(item, address);
        //other activities, such as updating inventory and charging the customer
    }
}
Non-transactional Resource
public class PackageDispatcher {
 
    @Inject
    OrderData orderData;
 
    @TxCompensate(RecallPackage.class)
    public void dispatch(String item, String address) {
 
        orderData.setAddress(address);
        orderData.setItem(item);
        //Dispatch the package
    }
}
Data
@CompensationScoped
public class OrderData implements Serializable {
 
    private String item;
    private String address;
    ...
}
Compensation Handler
public class RecallPackage implements CompensationHandler {
 
    @Inject
    OrderData orderData;
 
    @Override
    public void compensate() {
        //Recall the package somehow
    }
}
Cross-Domain Distributed
Transactions
•  Distribution => Increased chance of failure
•  Use transactions!
•  Distribution => Increased latency
•  Maybe not ACID transactions then
•  Cross-domain => loose coupling
•  ACID transactions => tight-coupling
Compensation-based transaction is an option
Code Example
•  Travel Agent
•  Coordinates:
•  Booking of a Taxi
•  Booking of a Hotel
•  Taxi and Hotel Service are remote Web Services
•  WS-BA
Client
public class Client {
@Compensatable
public void makeBooking() {
// Lookup Hotel and Taxi Web Service ports here...
hotelService.makeBooking("Double", "paul.robinson@redhat.com");
taxiService.makeBooking("Newcastle", "paul.robinson@redhat.com");
}
}
Service@WebService
public class HotelService {
@Inject BookingData bookingData;
@Compensatable(MANDATORY)
@TxCompensate(CancelBooking.class)
@TxConfirm(ConfirmBooking.class)
@Transactional(REQUIRES_NEW)
@WebMethod
public void makeBooking(String item, String user) {
//Update the database to mark the booking as pending…
bookingData.setBookingID("the id of the booking goes here");
}
}
Confirmation Handler
public class ConfirmBooking implements ConfirmationHandler {
@Inject
BookingData bookingData;
@Transactional(REQUIRES_NEW)
public void confirm() {
//Confirm order for bookingData.getBookingID() in Database (in a new JTA transaction)
}
}
Compensation Handler
public class CancelBooking implements CompensationHandler {
@Inject
BookingData bookingData;
@Transactional(REQUIRES_NEW)
public void compensate() {
//Cancel order for bookingData.getBookingID() in Database (in a new JTA transaction)
}
}
Long Lived Transactions (LLT)
•  ACID Transactions => all or nothing
•  OK for short lived transactions (SLT)
•  Failure in LLT leads to significant loss of work
•  Compensation-based Transactions
•  Split work into many SLT
•  Find alternative if one fails
•  Compensate all if no alternative
Code Example
•  Travel Agent
•  Coordinates:
•  Hotel service
•  2 Taxi Services
•  Aim to book 1xHotel & 1xTaxi
•  Hotel booking is important
Travel Agent Client
public class Agent {
@Inject ...
@Compensatable
public void makeBooking(String email, String room, String dest) throws BookingException {
hotelService.makeBooking(room, email);
try {
taxi1Service.makeBooking(dest, email);
} catch (BookingException e) {
taxi2Service.makeBooking(dest, email);
}
}
}
What we Have Today
•  Initial version of the API
•  @Compensatable
•  @CompensationScoped
•  LLT
•  Distribution over WS-BA
•  Quickstarts
•  All today’s examples
•  Blog post series
•  Available in:
•  Narayana 5.0.0.M4
•  WildFly 8.0.0.Alpha4
What we Have Planned
•  Support more complex use-cases
•  Feedback driven
•  Recovery
•  @CompensationScoped
•  JTA interop
•  EJB support
•  Specification
•  Throughput comparisons
•  2PC participants
•  NoSQL RM integration
Getting Started
•  Explore the quickstarts
•  http://github.com/jbosstm/quickstart/
•  Give feedback
•  http://community.jboss.org/en/jbosstm
•  Track issues
•  http://issues.jboss.org/browse/JBTM
•  TXFramework component
•  Subscribe to Blog
•  http://jbossts.blogspot.co.uk/
•  Contact me
•  paul.robinson@redhat.com, @pfrobinson

Más contenido relacionado

Similar a Compensating Transactions: When ACID is too much

Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
AOE
 
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
confluent
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
vmandrychenko
 

Similar a Compensating Transactions: When ACID is too much (20)

Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
Clean Architecture @ Taxibeat
Clean Architecture @ TaxibeatClean Architecture @ Taxibeat
Clean Architecture @ Taxibeat
 
RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis code
 
CDI in JEE6
CDI in JEE6CDI in JEE6
CDI in JEE6
 
ArchSummit Shenzhen - Using sagas to maintain data consistency in a microserv...
ArchSummit Shenzhen - Using sagas to maintain data consistency in a microserv...ArchSummit Shenzhen - Using sagas to maintain data consistency in a microserv...
ArchSummit Shenzhen - Using sagas to maintain data consistency in a microserv...
 
Geode Transactions by Swapnil Bawaskar
Geode Transactions by Swapnil BawaskarGeode Transactions by Swapnil Bawaskar
Geode Transactions by Swapnil Bawaskar
 
Geode transactions
Geode transactionsGeode transactions
Geode transactions
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuning
 
"An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done..."An introduction to object-oriented programming for those who have never done...
"An introduction to object-oriented programming for those who have never done...
 
Dont call me cache java version
Dont call me cache java versionDont call me cache java version
Dont call me cache java version
 
Code smells and remedies
Code smells and remediesCode smells and remedies
Code smells and remedies
 
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
Synchronous Commands over Apache Kafka (Neil Buesing, Object Partners, Inc) K...
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactions
 
Solidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding Practices
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 
Transaction design patterns
Transaction design patternsTransaction design patterns
Transaction design patterns
 
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
Real Object-Oriented Programming: Empirically Validated Benefits of the DCI P...
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchain
 
Refactoring - improving the smell of your code
Refactoring - improving the smell of your codeRefactoring - improving the smell of your code
Refactoring - improving the smell of your code
 

Más de JBUG London

Más de JBUG London (14)

London JBUG April 2015 - Performance Tuning Apps with WildFly Application Server
London JBUG April 2015 - Performance Tuning Apps with WildFly Application ServerLondon JBUG April 2015 - Performance Tuning Apps with WildFly Application Server
London JBUG April 2015 - Performance Tuning Apps with WildFly Application Server
 
WebSocketson WildFly
WebSocketson WildFly WebSocketson WildFly
WebSocketson WildFly
 
Hacking on WildFly 9
Hacking on WildFly 9Hacking on WildFly 9
Hacking on WildFly 9
 
Introduction to PicketLink
Introduction to PicketLinkIntroduction to PicketLink
Introduction to PicketLink
 
Extending WildFly
Extending WildFlyExtending WildFly
Extending WildFly
 
What's New in Infinispan 6.0
What's New in Infinispan 6.0What's New in Infinispan 6.0
What's New in Infinispan 6.0
 
London JBUG - Connecting Applications Everywhere with JBoss A-MQ
London JBUG - Connecting Applications Everywhere with JBoss A-MQLondon JBUG - Connecting Applications Everywhere with JBoss A-MQ
London JBUG - Connecting Applications Everywhere with JBoss A-MQ
 
Easy Integration with Apache Camel and Fuse IDE
Easy Integration with Apache Camel and Fuse IDEEasy Integration with Apache Camel and Fuse IDE
Easy Integration with Apache Camel and Fuse IDE
 
jBPM5 - The Evolution of BPM Systems
jBPM5 - The Evolution of BPM SystemsjBPM5 - The Evolution of BPM Systems
jBPM5 - The Evolution of BPM Systems
 
Arquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made EasyArquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made Easy
 
Infinispan from POC to Production
Infinispan from POC to ProductionInfinispan from POC to Production
Infinispan from POC to Production
 
Hibernate OGM - JPA for Infinispan and NoSQL
Hibernate OGM - JPA for Infinispan and NoSQLHibernate OGM - JPA for Infinispan and NoSQL
Hibernate OGM - JPA for Infinispan and NoSQL
 
JBoss jBPM, the future is now for all your Business Processes by Eric Schabell
JBoss jBPM, the future is now for all your Business Processes by Eric SchabellJBoss jBPM, the future is now for all your Business Processes by Eric Schabell
JBoss jBPM, the future is now for all your Business Processes by Eric Schabell
 
JBoss AS7 by Matt Brasier
JBoss AS7 by Matt BrasierJBoss AS7 by Matt Brasier
JBoss AS7 by Matt Brasier
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Compensating Transactions: When ACID is too much

  • 1.
  • 2. Compensating Transactions: When ACID is Too Much Dr Paul Robinson paul.robinson@redhat.com @pfrobinson
  • 3. Agenda •  Background •  Non-transactional resources •  Cross-domain distributed transactions •  Long-lived transactions •  What we have today & planned •  Getting started
  • 4. ACID Transactions Positives •  Strong guarantees •  Tolerate (certain) failures •  Easy API to develop against Negatives •  Blocking •  Can reduce throughput •  Requires two-phase aware resources •  Tight-coupling
  • 6. Don’t give up on transactions altogether!
  • 7. Extended Transactions •  Umbrella term •  Alternative to ACID •  Relaxes some ACID properties Guarantees None ACIDExtended
  • 8. Compensation-based Transactions •  Based on Sagas •  Academic research from 1987 •  ACID vs Compensation-based transactions •  ACID •  Phase <=1: acquire locks & log •  Phase 2: commit/rollback changes •  Compensation-based •  Phase <=1: commit changes & log •  Phase 2: confirm? / compensate change
  • 9. Hang on…. What effect does this have on Isolation and Consistency? Looks a bit dubious to me!
  • 12. Previous Support in Narayana •  WS-BusinessActivity •  Oasis Web Services standard •  Standardizes •  Message format •  State machine •  No API •  Problems? •  Web services only •  Low-level API
  • 13. Compensations API •  JTA-like API •  Application API only •  Maybe AS and RM in future •  Interop with JTA 1.2 •  Transport Neutral
  • 15. Non-Transactional Resources •  Transactional Resources •  Participate in a two-phase protocol •  Prepare and later commit/rollback •  Non-transactional resources •  Can’t participate in a two-phase protocol Compensation-based transaction is an option
  • 16. Code Example •  Ecommerce site, selling books •  Coordinates: •  Updating databases •  Dispatching package
  • 17. Service public class BookService {       @Inject     PackageDispatcher packageDispatcher ;       @Compensatable     public void buyBook(String item, String address) {           packageDispatcher.dispatch(item, address);         //other activities, such as updating inventory and charging the customer     } }
  • 18. Non-transactional Resource public class PackageDispatcher {       @Inject     OrderData orderData;       @TxCompensate(RecallPackage.class)     public void dispatch(String item, String address) {           orderData.setAddress(address);         orderData.setItem(item);         //Dispatch the package     } }
  • 19. Data @CompensationScoped public class OrderData implements Serializable {       private String item;     private String address;     ... }
  • 20. Compensation Handler public class RecallPackage implements CompensationHandler {       @Inject     OrderData orderData;       @Override     public void compensate() {         //Recall the package somehow     } }
  • 21. Cross-Domain Distributed Transactions •  Distribution => Increased chance of failure •  Use transactions! •  Distribution => Increased latency •  Maybe not ACID transactions then •  Cross-domain => loose coupling •  ACID transactions => tight-coupling Compensation-based transaction is an option
  • 22. Code Example •  Travel Agent •  Coordinates: •  Booking of a Taxi •  Booking of a Hotel •  Taxi and Hotel Service are remote Web Services •  WS-BA
  • 23. Client public class Client { @Compensatable public void makeBooking() { // Lookup Hotel and Taxi Web Service ports here... hotelService.makeBooking("Double", "paul.robinson@redhat.com"); taxiService.makeBooking("Newcastle", "paul.robinson@redhat.com"); } }
  • 24. Service@WebService public class HotelService { @Inject BookingData bookingData; @Compensatable(MANDATORY) @TxCompensate(CancelBooking.class) @TxConfirm(ConfirmBooking.class) @Transactional(REQUIRES_NEW) @WebMethod public void makeBooking(String item, String user) { //Update the database to mark the booking as pending… bookingData.setBookingID("the id of the booking goes here"); } }
  • 25. Confirmation Handler public class ConfirmBooking implements ConfirmationHandler { @Inject BookingData bookingData; @Transactional(REQUIRES_NEW) public void confirm() { //Confirm order for bookingData.getBookingID() in Database (in a new JTA transaction) } }
  • 26. Compensation Handler public class CancelBooking implements CompensationHandler { @Inject BookingData bookingData; @Transactional(REQUIRES_NEW) public void compensate() { //Cancel order for bookingData.getBookingID() in Database (in a new JTA transaction) } }
  • 27. Long Lived Transactions (LLT) •  ACID Transactions => all or nothing •  OK for short lived transactions (SLT) •  Failure in LLT leads to significant loss of work •  Compensation-based Transactions •  Split work into many SLT •  Find alternative if one fails •  Compensate all if no alternative
  • 28. Code Example •  Travel Agent •  Coordinates: •  Hotel service •  2 Taxi Services •  Aim to book 1xHotel & 1xTaxi •  Hotel booking is important
  • 29. Travel Agent Client public class Agent { @Inject ... @Compensatable public void makeBooking(String email, String room, String dest) throws BookingException { hotelService.makeBooking(room, email); try { taxi1Service.makeBooking(dest, email); } catch (BookingException e) { taxi2Service.makeBooking(dest, email); } } }
  • 30. What we Have Today •  Initial version of the API •  @Compensatable •  @CompensationScoped •  LLT •  Distribution over WS-BA •  Quickstarts •  All today’s examples •  Blog post series •  Available in: •  Narayana 5.0.0.M4 •  WildFly 8.0.0.Alpha4
  • 31. What we Have Planned •  Support more complex use-cases •  Feedback driven •  Recovery •  @CompensationScoped •  JTA interop •  EJB support •  Specification •  Throughput comparisons •  2PC participants •  NoSQL RM integration
  • 32. Getting Started •  Explore the quickstarts •  http://github.com/jbosstm/quickstart/ •  Give feedback •  http://community.jboss.org/en/jbosstm •  Track issues •  http://issues.jboss.org/browse/JBTM •  TXFramework component •  Subscribe to Blog •  http://jbossts.blogspot.co.uk/ •  Contact me •  paul.robinson@redhat.com, @pfrobinson