SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à Compensating Transactions: When ACID is too much

RedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedisConf18 - Writing modular & encapsulated Redis code
RedisConf18 - Writing modular & encapsulated Redis codeRedis Labs
 
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...Chris Richardson
 
Geode Transactions by Swapnil Bawaskar
Geode Transactions by Swapnil BawaskarGeode Transactions by Swapnil Bawaskar
Geode Transactions by Swapnil BawaskarPivotalOpenSourceHub
 
Performance measurement and tuning
Performance measurement and tuningPerformance measurement and tuning
Performance measurement and tuningAOE
 
"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...Fwdays
 
Dont call me cache java version
Dont call me cache java versionDont call me cache java version
Dont call me cache java versionAvisi B.V.
 
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
 
Grails transactions
Grails   transactionsGrails   transactions
Grails transactionsHusain Dalal
 
Solidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesSolidity Security and Best Coding Practices
Solidity Security and Best Coding PracticesGene Leybzon
 
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 PinterestPavan Chitumalla
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design PrinciplesJon Kruger
 
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...James Coplien
 
Security in the blockchain
Security in the blockchainSecurity in the blockchain
Security in the blockchainBellaj Badr
 
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 codevmandrychenko
 

Similaire à 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
 

Plus de JBUG London

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 ServerJBUG London
 
WebSocketson WildFly
WebSocketson WildFly WebSocketson WildFly
WebSocketson WildFly JBUG London
 
Hacking on WildFly 9
Hacking on WildFly 9Hacking on WildFly 9
Hacking on WildFly 9JBUG London
 
Introduction to PicketLink
Introduction to PicketLinkIntroduction to PicketLink
Introduction to PicketLinkJBUG London
 
Extending WildFly
Extending WildFlyExtending WildFly
Extending WildFlyJBUG London
 
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.0JBUG London
 
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-MQJBUG London
 
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 IDEJBUG London
 
jBPM5 - The Evolution of BPM Systems
jBPM5 - The Evolution of BPM SystemsjBPM5 - The Evolution of BPM Systems
jBPM5 - The Evolution of BPM SystemsJBUG London
 
Arquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made EasyArquillian - Integration Testing Made Easy
Arquillian - Integration Testing Made EasyJBUG London
 
Infinispan from POC to Production
Infinispan from POC to ProductionInfinispan from POC to Production
Infinispan from POC to ProductionJBUG London
 
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 NoSQLJBUG London
 
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 SchabellJBUG London
 
JBoss AS7 by Matt Brasier
JBoss AS7 by Matt BrasierJBoss AS7 by Matt Brasier
JBoss AS7 by Matt BrasierJBUG London
 

Plus 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
 

Dernier

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
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...apidays
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
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 2024The Digital Insurer
 
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 educationjfdjdjcjdnsjd
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
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...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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 businesspanagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
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 Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 

Dernier (20)

Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
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
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
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...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

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