SlideShare a Scribd company logo
Essential API Facade Patterns
Episode 3 – One Phase to Two Phase
Conversion



Santanu Dey                           Apigee
@Santanu_Dey                         @apigee
groups.google.com/group/api-craft
slideshare.net/apigee
youtube.com/apigee
@Santanu_Dey
 Santanu Dey
Webcast Series: API Facade Patterns


Episode 1
Composition

Episode 2
Session Management

Episode 3
One Phase to Two Phase Conversion

Episode 4
Synchronous to Asynchronous
Episode 3 : One-Phase to Two-Phase Conversion




Problem
Solution
Benefits
Considerations
Problem




How to expose a single phase API out of a two phase API


   To enable API teams and app developers to implement and
   improve their API designs and apps
Problem




From the point of view of the API provider, how to
expose a single phase API out of a two phase API

                                 1
   One Phase                             Two Phase
   Consumer                      2
                                          Provider
What is a Two Phase Interface?
First Phase – Prepare (or Vote)

                                   Participating
               prepare              Resource 1



                         prepare
                                            Participating
    Tx Coordinator                           Resource 2


                         prepare


                                      Participating
                                       Resource 3
Second Phase - Commit

                               Participating
                                Resource 1
             commit



                      commit            Participating
   Tx Coordinator                        Resource 2


                      commit



                                  Participating
                                   Resource 3
Two phase commit works well for server-side
distributed architecture
Not such a good idea for an app to consume a
two-phase API


                     prepare

                                       Service
        App
                                       Provider
                      commit
Transaction reliability is seldom a requirement for a
JavaScript plugin or an app
Making the app a transaction coordinator is asking the
developer to do too much

- to think about roll back, compensation etc.

-device runtime not well suited for heavy programming logic
Problems with Service Composition on Device

“chatty service” anti-pattern – multiple callouts from
client app to multi services


                  1. Get user attributes
                  2. Get recommended topics                 API
                                                          Provider
                  3. Get recommended books
  Client
           Network connection, negotiate security, data
           format & parsing
Problems with Service Composition on Device

                         Heavy data usage
                      Too many network calls
                           Battery drain
                           Performance
                     1. Get user attributes
                     2. Get recommended topics                      API
                     3. Get recommended books                     Provider


 Client
          Network connection, negotiate security, data format &
          parsing
Solution
One Phase to Two Phase Conversion using API Façade




The solution is to introduce an API Façade in the middle
which can handle the conversion

                                 1
   One Phase                             Two Phase
   Consumer                      2
                                          Provider
One Phase to Two Phase Conversion using API Façade




                                   1
 One Phase                                Two Phase
 Consumer                          2
                                           Provider




/reserve
/payment
One Phase to Two Phase Conversion using API Façade




                                   1
 One Phase                                Two Phase
 Consumer                          2
                                           Provider




/payment
Warning! UML Ahead
Essential API Facade Patterns: One Phase to Two Phase Conversion (Episode 3)
If I am missing something, please let me know, but for
now I consider ”REST transaction" to be an
oxymoron.

- Roy Fielding
Example of the API Façade


                          API Façade




                        API
                                    Existing     Backend
                     Exposure &
                                  Capabilities    Server
                       Mgmt.

App relies on REST
Benefits
Re-use existing enterprise backend
The client app avoids complexities like managing
transactions = Lovable API
Distributed Transaction Management

                                     1
                                         Two Phase
                                     2
                                          Provider


  One Phase
  Consumer

                                     1
                                         Two Phase
                                     2
                                          Provider
Resource states do not need to be maintained
Other Considerations
What is the trade-off?


Ability to coordinate distributed transaction from the client
Is it Possible to Expose Two-Phase API in REST?
Here is an Example
 POST /transfer/transaction
 {”from":”account1”, ”to”:”account2”, "amount":100}

 Response:
 {"id":"/transfer/transaction/123", "state":”started", blah blah}



 PUT /transfer/transaction/123
 {"id":"/transfer/transaction/123", "state":"committed", ...}

 Response:
 {"id":"/transfer/transaction/123", "state":”comitted", blah blah}
Questions?
THANK YOU
Subscribe to API webcasts at:
youtube.com/apigee



                                 Apigee
                                @apigee
THANK YOU
Questions and ideas to:
groups.google.com/group/api-craft



                                     Apigee
                                    @apigee
THANK YOU
Contact me at:

@Santanu_Dey
sdey@apigee.com




                   Apigee
                  @apigee

More Related Content

PPTX
éTica y política en la filosofía de platón
PPTX
Essential API Facade Patterns - Composition (Episode 1)
PPTX
Essential API Facade Patterns: Session Management (Episode 2)
PPTX
The API Facade Pattern: Common Patterns - Episode 2
PPTX
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
PPTX
HTML5: The Apps, the Frameworks, the Controversy
PPTX
The Anatomy of Apps - How iPhone, Android & Facebook Apps Consume APIs
PPTX
Skeuomorphs, Databases, and Mobile Performance
éTica y política en la filosofía de platón
Essential API Facade Patterns - Composition (Episode 1)
Essential API Facade Patterns: Session Management (Episode 2)
The API Facade Pattern: Common Patterns - Episode 2
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
HTML5: The Apps, the Frameworks, the Controversy
The Anatomy of Apps - How iPhone, Android & Facebook Apps Consume APIs
Skeuomorphs, Databases, and Mobile Performance

Viewers also liked (19)

PPTX
Visbility at the Edge - Deep Insights from Your API
PPTX
The API Facade Pattern: People - Episode 4
PPT
Crafting APIs for Mobile Apps - Everything You Need to Know
PPT
Building your first Native iOs App with an API Backend
PPTX
Driving Digital Success: Three ROI Criteria for Competitive Advantage
PPTX
The New 3-Tier Architecture: HTML5, Proxies, and APIs
PDF
The Walgreens Story: Putting an API Around Their Stores (Webcast)
PPTX
Telco Innovation with APIs - Need for speed (Webcast)
PPTX
APIs Inside Enterprise - SOA Displacement?
PPTX
DevOps & Apps - Building and Operating Successful Mobile Apps
PPTX
Economic Models for Reinventing Telco - Innovation with APIs
PPTX
API Management for Software Defined Network (SDN)
PPTX
OData Introduction and Impact on API Design (Webcast)
PPTX
APIs & Copyrights
PDF
How to (almost certainly) fail: Building vs. buying your API infrastructure
PPTX
The API Facade Pattern: Overview - Episode 1
PPTX
API Design - 3rd Edition
PPTX
API Product Management - Driving Success through the Value Chain
DOCX
Field Study 4 Episode 3
Visbility at the Edge - Deep Insights from Your API
The API Facade Pattern: People - Episode 4
Crafting APIs for Mobile Apps - Everything You Need to Know
Building your first Native iOs App with an API Backend
Driving Digital Success: Three ROI Criteria for Competitive Advantage
The New 3-Tier Architecture: HTML5, Proxies, and APIs
The Walgreens Story: Putting an API Around Their Stores (Webcast)
Telco Innovation with APIs - Need for speed (Webcast)
APIs Inside Enterprise - SOA Displacement?
DevOps & Apps - Building and Operating Successful Mobile Apps
Economic Models for Reinventing Telco - Innovation with APIs
API Management for Software Defined Network (SDN)
OData Introduction and Impact on API Design (Webcast)
APIs & Copyrights
How to (almost certainly) fail: Building vs. buying your API infrastructure
The API Facade Pattern: Overview - Episode 1
API Design - 3rd Edition
API Product Management - Driving Success through the Value Chain
Field Study 4 Episode 3
Ad

Similar to Essential API Facade Patterns: One Phase to Two Phase Conversion (Episode 3) (20)

PDF
Document
KEY
Extend Your Use of JIRA by Solving Your Unique Concerns: An Exposé of the New...
KEY
Extend Your Use of JIRA by Solving Your Unique Concerns: An Exposé of the New...
PDF
005281271.pdf
PPTX
OpenStack-Based NFV Cloud at Swisscom: challenges and best practices
PDF
Chapter2[one.]
PPT
Chapter2 application
PDF
App Engine overview (Android meetup 06-10)
PPT
Week3 applications
PDF
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
PDF
2021 JCConf 使用Dapr簡化Java微服務應用開發
PDF
APIdays Paris 2018 - Autonomous APIs, Zdenek Nemec, Founder, Good API
PDF
Project Fedena and Why Ruby on Rails - ArvindArvind G S
PPTX
eBay From Ground Level to the Clouds
PPTX
WEB API Gateway
PPTX
apidays LIVE India - Asynchronous and Broadcasting APIs using Kafka by Rohit ...
PDF
Kubernetes_Webinar_Slide_Deck.pdf
PDF
How to Introduce Continuous Delivery
PDF
JavaOne 2016: Kubernetes introduction for Java Developers
PDF
Kubernetes for Java Developers
Document
Extend Your Use of JIRA by Solving Your Unique Concerns: An Exposé of the New...
Extend Your Use of JIRA by Solving Your Unique Concerns: An Exposé of the New...
005281271.pdf
OpenStack-Based NFV Cloud at Swisscom: challenges and best practices
Chapter2[one.]
Chapter2 application
App Engine overview (Android meetup 06-10)
Week3 applications
Fundamental Spring Boot: Keep it Simple, Get it Right, Be Productive and Have...
2021 JCConf 使用Dapr簡化Java微服務應用開發
APIdays Paris 2018 - Autonomous APIs, Zdenek Nemec, Founder, Good API
Project Fedena and Why Ruby on Rails - ArvindArvind G S
eBay From Ground Level to the Clouds
WEB API Gateway
apidays LIVE India - Asynchronous and Broadcasting APIs using Kafka by Rohit ...
Kubernetes_Webinar_Slide_Deck.pdf
How to Introduce Continuous Delivery
JavaOne 2016: Kubernetes introduction for Java Developers
Kubernetes for Java Developers
Ad

More from Apigee | Google Cloud (20)

PDF
How Secure Are Your APIs?
PDF
Magazine Luiza at a glance (1)
PPTX
Monetization: Unlock More Value from Your APIs
PDF
Apigee Demo: API Platform Overview
PDF
Ticketmaster at a glance
PDF
AccuWeather: Recasting API Experiences in a Developer-First World
PDF
Which Application Modernization Pattern Is Right For You?
PPTX
Apigee Product Roadmap Part 2
PPTX
The Four Transformative Forces of the API Management Market
PDF
Walgreens at a glance
PDF
Apigee Edge: Intro to Microgateway
PDF
Managing the Complexity of Microservices Deployments
PDF
Pitney Bowes at a glance
PPTX
Microservices Done Right: Key Ingredients for Microservices Success
PDF
Adapt or Die: Opening Keynote with Chet Kapoor
PDF
Adapt or Die: Keynote with Greg Brail
PDF
Adapt or Die: Keynote with Anant Jhingran
PDF
London Adapt or Die: Opening Keynot
PDF
London Adapt or Die: Lunch keynote
PDF
London Adapt or Die: Closing Keynote — Adapt Now!
How Secure Are Your APIs?
Magazine Luiza at a glance (1)
Monetization: Unlock More Value from Your APIs
Apigee Demo: API Platform Overview
Ticketmaster at a glance
AccuWeather: Recasting API Experiences in a Developer-First World
Which Application Modernization Pattern Is Right For You?
Apigee Product Roadmap Part 2
The Four Transformative Forces of the API Management Market
Walgreens at a glance
Apigee Edge: Intro to Microgateway
Managing the Complexity of Microservices Deployments
Pitney Bowes at a glance
Microservices Done Right: Key Ingredients for Microservices Success
Adapt or Die: Opening Keynote with Chet Kapoor
Adapt or Die: Keynote with Greg Brail
Adapt or Die: Keynote with Anant Jhingran
London Adapt or Die: Opening Keynot
London Adapt or Die: Lunch keynote
London Adapt or Die: Closing Keynote — Adapt Now!

Essential API Facade Patterns: One Phase to Two Phase Conversion (Episode 3)

  • 1. Essential API Facade Patterns Episode 3 – One Phase to Two Phase Conversion Santanu Dey Apigee @Santanu_Dey @apigee
  • 6. Webcast Series: API Facade Patterns Episode 1 Composition Episode 2 Session Management Episode 3 One Phase to Two Phase Conversion Episode 4 Synchronous to Asynchronous
  • 7. Episode 3 : One-Phase to Two-Phase Conversion Problem Solution Benefits Considerations
  • 8. Problem How to expose a single phase API out of a two phase API To enable API teams and app developers to implement and improve their API designs and apps
  • 9. Problem From the point of view of the API provider, how to expose a single phase API out of a two phase API 1 One Phase Two Phase Consumer 2 Provider
  • 10. What is a Two Phase Interface?
  • 11. First Phase – Prepare (or Vote) Participating prepare Resource 1 prepare Participating Tx Coordinator Resource 2 prepare Participating Resource 3
  • 12. Second Phase - Commit Participating Resource 1 commit commit Participating Tx Coordinator Resource 2 commit Participating Resource 3
  • 13. Two phase commit works well for server-side distributed architecture
  • 14. Not such a good idea for an app to consume a two-phase API prepare Service App Provider commit
  • 15. Transaction reliability is seldom a requirement for a JavaScript plugin or an app
  • 16. Making the app a transaction coordinator is asking the developer to do too much - to think about roll back, compensation etc. -device runtime not well suited for heavy programming logic
  • 17. Problems with Service Composition on Device “chatty service” anti-pattern – multiple callouts from client app to multi services 1. Get user attributes 2. Get recommended topics API Provider 3. Get recommended books Client Network connection, negotiate security, data format & parsing
  • 18. Problems with Service Composition on Device Heavy data usage Too many network calls Battery drain Performance 1. Get user attributes 2. Get recommended topics API 3. Get recommended books Provider Client Network connection, negotiate security, data format & parsing
  • 20. One Phase to Two Phase Conversion using API Façade The solution is to introduce an API Façade in the middle which can handle the conversion 1 One Phase Two Phase Consumer 2 Provider
  • 21. One Phase to Two Phase Conversion using API Façade 1 One Phase Two Phase Consumer 2 Provider /reserve /payment
  • 22. One Phase to Two Phase Conversion using API Façade 1 One Phase Two Phase Consumer 2 Provider /payment
  • 25. If I am missing something, please let me know, but for now I consider ”REST transaction" to be an oxymoron. - Roy Fielding
  • 26. Example of the API Façade API Façade API Existing Backend Exposure & Capabilities Server Mgmt. App relies on REST
  • 29. The client app avoids complexities like managing transactions = Lovable API
  • 30. Distributed Transaction Management 1 Two Phase 2 Provider One Phase Consumer 1 Two Phase 2 Provider
  • 31. Resource states do not need to be maintained
  • 33. What is the trade-off? Ability to coordinate distributed transaction from the client
  • 34. Is it Possible to Expose Two-Phase API in REST?
  • 35. Here is an Example POST /transfer/transaction {”from":”account1”, ”to”:”account2”, "amount":100} Response: {"id":"/transfer/transaction/123", "state":”started", blah blah} PUT /transfer/transaction/123 {"id":"/transfer/transaction/123", "state":"committed", ...} Response: {"id":"/transfer/transaction/123", "state":”comitted", blah blah}
  • 37. THANK YOU Subscribe to API webcasts at: youtube.com/apigee Apigee @apigee
  • 38. THANK YOU Questions and ideas to: groups.google.com/group/api-craft Apigee @apigee
  • 39. THANK YOU Contact me at: @Santanu_Dey sdey@apigee.com Apigee @apigee

Editor's Notes

  • #6: I am Santanu DeyI am a senior solution architect here at Apigee – I am focused on Integration – primarily API based Integration & and a little bit beyond
  • #10: As an API Provider we often come across a situation where the backend core system exposes a 2 phase Interface – for simplicity of consumption we have to convert it to one phase REST APIWHY DO WE WANT TO DO THIS?The essence of API integration over enterprise style integration is extra emphasis on simplicity. So if it makes it easy for a Developer to consume the API – lets better make it simple.Traditionally Enterprise systems expose interfaces compatible with 2 phase commit. 2 phase commit is a very well established pattern. This is very useful for designing transactions in a reliable way. But these are not so appropriate for the edge of the enterprise. Where innovation is driven by ease of consumption of resources. The underlying enterprise integration tools should not dictate how APIs are defined, exposed and integrated. That is the core motivation for this pattern.
  • #11: It is common for backend Interfaces running on enterprise integration software exposes a two phase interface. From the perspective of the distributed transactions – when an Interface supports two phase commit we can say it is a two phase API
  • #12: A quick and high-level recap how a typical tow phase transaction work in the distributed transaction scenario– there are two types of resources. A transaction coordinator or a transaction Manager. And then the participating resources.At the core of two phase distributed transaction - each participating resource supports two phases – to be able to participate in a distributed two phase transaction.How does it all happen?Prepare or vote - A “commit” vote means that participants can carry out the commit if told to – there is no inconsistency or exception expected from that component
  • #13: Commit or Rollback. In this phase, the transaction coordinator instructs each of the participating resourcesto commit or rollback all of the changes that were requested as part of the transaction. A properly executed rollback should return the system to its original state.A commit should result into a consistent state of change across systems.
  • #14: This makes a lot of sense for machine to machine communication in a distributed architectureIn order to reliably carry out distributed transactions – this is a great pattern. A two phase commit that is. But the key question is that is it a good idea for an app to consume a two phase enabled API?
  • #15: I think it is not a good idea for an app to consume a two phase API interface.It is like getting an app to become a transaction coordinator because the API provider supports two phase it is not a great ideaFirst of all When looking into REST one of the first things probably anybody will notice is there isn't any transaction semantics defined. Unlike WS-Transactions for web services.Let us see why it does not sound like a good idea
  • #16: The important one is this –Consider a typical appA browser plugin may be written in java script, an app running on a device or an HTML 5 need have Transactional behavior? Let me emphasize more on the use case in question. Not so much on the technology employed. Are there any real use cases?Let us think about a two phase API example. Thinking about transactions – payment comes in mind. Consider GSMA OneAPI Payment API – the mobile payment API - Yes it has two phases. But in most scenarios – the Developer server is expected to make the calls. So it is a machine to machine architecture. Not a client application to API host.
  • #17: Secondly, making the app a transaction coordinator is kind of forcing the developer to think about roll back, compensation etc.The device run-time is not best suited for heavy logic needed for a two phase commit, roll back or compensationLack of simplicity in the APIs would make it difficult for the developer
  • #18: The Service Composition pattern in Episode 1 listed the other disadvantages of composing multiple service calls from the device – this situation also applies to this case. At least partially here the connections are to the same server….
  • #22: let us assume that the backend has a two phase interface- > Reserve an amount for payment- > Commit the paymentOne of the ways to convert this interface to REST kind of semantics is to just convert the resources to two appropriate corresponding APIs. Like I have shown in the slide. And yes – there would be a way to get the payment resource location as a representation in the reserve response. But this is still away from REST for the problems sighted in the problem segment of our discussion.
  • #23: So the suggested pattern is to not to get influenced by what the backend API signature looks likeThe API Façade should still expose a single resource
  • #25: UML sequence diagram to explain the responsibilities of the API Façade layer in this pattern.Point to note that the transaction management responsibility has shifted to the API façade The client has to only deal with one resource and one pure REST call.What I have not shown here is that the API façade also can do a bunch of things when the transaction go wrong. And at the end just throw a much simpler error back to the client.
  • #26: We are not recommending a two phase REST API or “transactional REST APIs”
  • #27: The Façade is a logical construct in terms of the architecture. It can be implemented by number of software components such as Application servers, databases, API management & exposure layer, analytics and so on. The good news is that the Façade Layer does not need to rebuild all the existing capabilities. The API Service Layer is a Façade on top of the existing capabilities. I wanted to make it clear that we show this layer as a single component – but that is just a logical representation.
  • #29: If the API provider has EAI style two phase interfaces – using this pattern those can be re-used for exposing through the edge of the enterprise for the partners and consumers outside the organization.Backend does not need to changeOff-late we are seeing that the API programs are also opening up internal integration opportunities. Remember the “eat your own dog food” phrase? So even internal consumers who prefers REST over EAI should be able to consume the services through this pattern.
  • #30: The second benefit is ease of use. Once we are truly REST it is much easier for the consumer to use an APIThe client deals with one resource at a time, instead of attempting to be a transaction manager of a sort.The responsibilities of transaction management if at all, is deferred to the API Façade.I am not even highlighting the other standard benefits of moving the composition responsibilities into the Façade – lower network calls from device, lower processing and all that. But let us look at the transaction management angle
  • #31: This is an extended example of the same pattern – Here the api façade is responsible for coordinating a distributed transaction. However exposes only a single REST resource for the client.So the API façade takes care of the transaction roll back and compensation scenarios as well.Instead of looking for a "transaction protocol" over REST and HTTP, we should consider a resource that is acting as a coordinator. The client can then ask that coordinator resource do manage changes across those other resources atomically or in whatever manner makes sense for the application. The façade exposes the resource coordinators as REST resources themselvesAs far as the client is concerned, it is not aware of any distributed transaction protocol. There more complexities than just transaction management The backends may require security protocols that are not expensive for an AppThere may be rules associated with transaction timeout, rollback that the Façade can take care of
  • #32: If we had exposed two phase API through the API Façade the Façade layer then had to maintain resource lock and resource stateThis leads to better performance and scalability of the Façade layer itself.Being freed from client specific state management the Façade layer can scale well.
  • #34: What do we give up while taking this approach?If the use case really warrants a reliable kind of transaction management – REST may not be a good choice. But there are some examples are coming up on exposing REST APIs with transactional behaviour..
  • #36: This is still a semantics – to support REST format transaction – The detail is in implementation and real world use casesThat is something that still can be brainstormed. With this food for thought I will conclude