SlideShare una empresa de Scribd logo
1 de 51
Descargar para leer sin conexión
Chapter 2
Using an API Gateway
Designing and Deploying Microservices
1
by Chris Richardson
2
1. Number of items in the shopping cart
2. Order history
3. Customer reviews
4. Low inventory warning
5. Shipping options
6. Various recommendations, including other products this product is frequently
bought with, other products bought by customers who bought this product,
and other products viewed by customers who bought this product
7. Alternative purchasing options
3
GET api.company.com/productdetails/productId
Monolithic application architecture
A load balancer routes the request to one of several identical application
instances. The application then queries various database tables and
return the response to the client
4
Microservices Architecture
● Shopping Cart Service – Number of items in the shopping cart
● Order Service – Order history
● Catalog Service – Basic product information, such as product name, image,
and price
● Review Service – Customer reviews
● Inventory Service – Low inventory warning
● Shipping Service – Shipping options, deadlines, and costs, drawn separately
from the shipping provider’s API
● Recommendation Service(s) – Suggested items
5
6
https://serviceName.api.company.name
Direct Client-to-Microservice Communication
Each microservice would have a public endpoint.
7
shopcart.api.abc.com
shipping.api.abc.com
inventory.api.abc.com
order.api.abc.com
recom.api.abc.com
review.api.abc.com
catalog.api.abc.com
8
Direct Client-to-Microservice
Communication
9
The First Problem is
the mismatch between the needs of the client and the
fine-grained APIs exposed by each of the microservices.
10
The First Problem
1. The client in this example has to make seven separate requests.
○ For example, Amazon describes how hundreds of services are involved in rendering their
product page.
2. Too inefficient over the public Internet
11
一個頁面要七個請求
一個頁面要二十個請求
一個頁面要一百個請求
The Second Problem is
the client directly calling the microservices is that some
might use protocols that are not web-friendly.
12
1. One service might use Thrift binary RPC while another service might use the
AMQP messaging protocol.
2. An application should use protocols such as HTTP and WebSocket outside
of the firewall.
The Second Problem
Apache Thrift
13
The Third Problem is
it makes it difficult to refactor the microservices.
14
The Thrid Problem
1. Over time we might want to change how the system is partitioned into
services. For example, we might merge two services or split a service into
two or more services.
2. The clients communicate directly with the services, then performing this kind
of refactoring can be extremely difficult.
15
Direct Client-to-Microservice Communication
1. fine-grained APIs exposed
2. protocols are not web-friendly.
3. difficult to refactor
16
17
Using an API Gateway
18
What is an API Gateway?
● Single entry point into the system
● similar to Facade pattern from OOD.
● other responsibilities such as authentication, monitoring, load balancing,
caching, request shaping and management, and static response handling
19
api.abc.com
20
Amazon API Gateway
Single Entry Point
21
Overview API Gateway
Microservices on AWS (AWS Whitepaper, PDF)
22
Facade Pattern
http://teddy-chen-tw.blogspot.com/2013/08/facade-pattern.html 23
http://teddy-chen-tw.blogspot.com/2013/08/facade-pattern.html 24
簡單說:就是個大門,而且只有一個
Authencation (鑰匙)
Monitoring (監控)
Cache (玄關)
Management (櫃檯)
...
25
26
The API Gateway is responsible for
1. request routing: routes requests to the appropriate microservice.
2. composition: The API Gateway will often handle a request by invoking
multiple microservices and aggregating the results
3. protocol translation: It can translate between web protocols such as HTTP
and WebSocket and web-unfriendly protocols that are used internally.
27
API Composition
https://microservices.io/patterns/data/api-composition.html
28
1. a mobile client to retrieve all of the
product details with a single
request.
2. The API Gateway handles the
request by invoking the various
services – product information,
recommendations, reviews, etc –
and combining the results
1. The Netflix streaming service is available on hundreds of different kinds of
devices including televisions, set-top boxes, smartphones, gaming systems,
tablets, etc.
2. provide a one-size-fits-all API for their streaming service.
3. they use an API Gateway that provides an API tailored for each device by
running device-specific adapter code. An adapter typically handles each
request by invoking, on average, six to seven backend services.
Example: Nextflix API Gateway
29
Benefits and Drawbacks
of an API Gateway
30
Benefits
● A major bene t of using an API Gateway is that it encapsulates the internal
structure of the application.
● The API Gateway provides each kind of client with a specific API. This
reduces the number of round trips between the client and application. It
also simplifies the client code.
31
Drawbacks
● It is yet another highly available component that must be developed,
deployed, and managed.
● There is also a risk that the API Gateway becomes a development
bottleneck.
32
Notes
● It is important that the process for updating the API Gateway be as
lightweight as possible. (Deployment and Operational)
● Despite these drawbacks, however, for most real-world applications it makes
sense to use an API Gateway.
33
34
Implementing an API Gateway
(賣產品)
35
Performance and Scalability
● Only a handful of companies operate at the scale of Netflix and need to
handle billions of requests per day.
● It makes sense, therefore, to build the API Gateway on a platform that
supports asynchronous, non-blocking I/O.
● On the JVM you can use one of the NIO-based frameworks such Netty,
Vertx, Spring Reactor, or JBoss Undertow. One popular non-JVM option is
Node.js.
● NGINX Plus o ers a mature, scalable, high-performance web server and
reverse proxy that is easily deployed, configured, and programmed.
36
37
https://microservices.io/patterns/data/api-composition.html
Authencation before
Validation the request
using the traditional async callback
approach quickly leads you to
callback hell.
Using a Reactive Programming Model
● CompletableFuture in Java 8
● Promise in JavaScript
● Reactive Extensions (also called Rx or ReactiveX), in Microsoft.NET
Platform
38
Service Invocation
● A microservices-based application is a distributed system and must use an
inter-process communication (IPC, Chapter 3) mechanism.
○ One option is to use an asynchronous, messaging-based mechanism. Some
implementations use a message broker such as JMS or AMQP. Others, such as Zeromq, are
brokerless and the services communicate directly.
○ The other style of inter-process communication is a synchronous mechanism such as HTTP
or Thrift.
● Consequently, the API Gateway will need to support a variety of
communication mechanisms.
39
Service Discovery
● The API Gateway needs to know the location (IP address and port) of each microservice with which
it communicates.
● in a modern, cloud-based microservices application, finding the needed locations is a non-trivial
problem.
● determining the location of an application service is not so easy, because of autoscaling and
upgrades.
● service discovery mechanism: either server-side discovery or client-side discovery Chapter 4
40
Amazon API Gateway
Single Entry Point
41Overview API Gateway
Resource Discovery on AWS
42
● Security Groups
● IAM Roles
● Resource Tags
● AWS SDK / CLI
Ops as Code with AWS CLI
TAG="ops:status"
VALUE="retired"
# 找出標記 retire 的機器
aws ec2 describe-instances 
--query 'Reservations[*].Instances[*].[InstanceId]' 
--filters Name=tag:$TAG,Values=$VALUE
--output text |
while IFS= read -r item
do
# 把 termination protection 關掉
aws ec2 modify-instance-attribute 
--instance-id $item 
--no-disable-api-termination
# terminate EC2 instance
aws ec2 terminate-instances --instance-ids $item
done
Handling Partial Failures
● This issue arises in all distributed systems whenever one service calls
another service that is either responding slowly or is unavailable.
● For example, if the recommendation service is unresponsive in the product details scenario, the API
Gateway should return the rest of the product details to the client since they are still useful to the
user.
● The API Gateway could also return cached data if that is available.
43
Netflix Hystrix (豪豬)
● Hystrix is a latency and fault tolerance library designed to isolate points of access to remote
systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex
distributed systems where failure is inevitable.
● implement circuit breaker pattern
● If the error rate for a service exceeds a specified threshold, Hystrix trips the circuit breaker and all
requests will fail immediately for a specified period of time. (service 的 error rate 超過指定的臨界
值,Hystrix 跳開斷路器,在一段時間之 內立即中短所有的請求。 )
● JVM base.
44
補充:Service Mesh
● 一種基礎架構 (infrastructure layer) 的服務,負責處理的是 Service 跟 Service 之間通訊的安全、可靠、速度。
● 現代網路的基礎協議是 TCP/IP,Microservice 的通訊就是 Service Mesh
45
Implementation: Envoy
46
Summary
47
48
1. makes sense to implement an API Gateway which acts as a single entry
point into a system
2. responsible for request routing, composition, and protocol translation
3. provides each of the application’s clients with a custom API.
4. mask failures in the backend services by returning cached or default data
API Gateway Features
49
https://konghq.com/kong-community-edition/
50
https://docs.microsoft.com/zh-tw/dotnet/standard/microservices-architecture/architect-microservice-container-ap
ions/direct-client-to-microservice-communication-versus-the-api-gateway-pattern
Reference
● Microservices.io
● Production-Ready Microservices (Free, 120+)
● Building Microservices
● Microservice Patterns (Manning) - MEAP
● Microservices on AWS (AWS Whitepaper, PDF)
● AWS re:Invent 2017: Building Microservice on AWS
● AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture
Patterns
51

Más contenido relacionado

La actualidad más candente

How to Overcome Data Challenges When Refactoring Monoliths to Microservices
How to Overcome Data Challenges When Refactoring Monoliths to MicroservicesHow to Overcome Data Challenges When Refactoring Monoliths to Microservices
How to Overcome Data Challenges When Refactoring Monoliths to Microservices
VMware Tanzu
 
Cloud-Native Fundamentals: Accelerating Development with Continuous Integration
Cloud-Native Fundamentals: Accelerating Development with Continuous IntegrationCloud-Native Fundamentals: Accelerating Development with Continuous Integration
Cloud-Native Fundamentals: Accelerating Development with Continuous Integration
VMware Tanzu
 
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
VMware Tanzu
 

La actualidad más candente (20)

Meetup milano #4 log management and anypoint advanced monitoring
Meetup milano #4   log management and anypoint advanced monitoringMeetup milano #4   log management and anypoint advanced monitoring
Meetup milano #4 log management and anypoint advanced monitoring
 
Driving success in the cloud with NGINX
Driving success in the cloud with NGINXDriving success in the cloud with NGINX
Driving success in the cloud with NGINX
 
How to Overcome Data Challenges When Refactoring Monoliths to Microservices
How to Overcome Data Challenges When Refactoring Monoliths to MicroservicesHow to Overcome Data Challenges When Refactoring Monoliths to Microservices
How to Overcome Data Challenges When Refactoring Monoliths to Microservices
 
Continuous Delivery to the Cloud: Automate Thru Production with CI + Spinnaker
Continuous Delivery to the Cloud: Automate Thru Production with CI + SpinnakerContinuous Delivery to the Cloud: Automate Thru Production with CI + Spinnaker
Continuous Delivery to the Cloud: Automate Thru Production with CI + Spinnaker
 
Api Gateway
Api GatewayApi Gateway
Api Gateway
 
Cloud-Native Fundamentals: Accelerating Development with Continuous Integration
Cloud-Native Fundamentals: Accelerating Development with Continuous IntegrationCloud-Native Fundamentals: Accelerating Development with Continuous Integration
Cloud-Native Fundamentals: Accelerating Development with Continuous Integration
 
Application delivery controllers
Application delivery controllersApplication delivery controllers
Application delivery controllers
 
Agile Integration Workshop
Agile Integration WorkshopAgile Integration Workshop
Agile Integration Workshop
 
3298 microservices and how they relate to esb api and messaging - inter con...
3298   microservices and how they relate to esb api and messaging - inter con...3298   microservices and how they relate to esb api and messaging - inter con...
3298 microservices and how they relate to esb api and messaging - inter con...
 
Java Application Modernization Patterns and Stories from the IBM Garage
Java Application Modernization Patterns and Stories from the IBM GarageJava Application Modernization Patterns and Stories from the IBM Garage
Java Application Modernization Patterns and Stories from the IBM Garage
 
IBM Hybrid Integration Platform
IBM Hybrid Integration PlatformIBM Hybrid Integration Platform
IBM Hybrid Integration Platform
 
Accelerate Digital Transformation with Pivotal Cloud Foundry on Azure
Accelerate Digital Transformation with Pivotal Cloud Foundry on AzureAccelerate Digital Transformation with Pivotal Cloud Foundry on Azure
Accelerate Digital Transformation with Pivotal Cloud Foundry on Azure
 
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
Four Steps Toward a Safer Continuous Delivery Practice (Hint: Add Monitoring)
 
Blockchain, Integration, Serverless, Microservices - OOW / Code One 2018 Review
Blockchain, Integration, Serverless, Microservices - OOW / Code One 2018 ReviewBlockchain, Integration, Serverless, Microservices - OOW / Code One 2018 Review
Blockchain, Integration, Serverless, Microservices - OOW / Code One 2018 Review
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
Accenture tech vision 2018 slideshare trend4_frictionless-biz_aw_a_mc
Accenture tech vision 2018 slideshare trend4_frictionless-biz_aw_a_mcAccenture tech vision 2018 slideshare trend4_frictionless-biz_aw_a_mc
Accenture tech vision 2018 slideshare trend4_frictionless-biz_aw_a_mc
 
Cloud-Native Workshop New York- Pivotal
Cloud-Native Workshop New York- PivotalCloud-Native Workshop New York- Pivotal
Cloud-Native Workshop New York- Pivotal
 
Microservices Architecture & Testing Strategies
Microservices Architecture & Testing StrategiesMicroservices Architecture & Testing Strategies
Microservices Architecture & Testing Strategies
 
IBM Cloud Direct Link 2.0
IBM Cloud Direct Link 2.0IBM Cloud Direct Link 2.0
IBM Cloud Direct Link 2.0
 
Secure, Strengthen, Automate, and Scale Modern Workloads with Red Hat & NGINX
Secure, Strengthen, Automate, and Scale Modern Workloads with Red Hat & NGINXSecure, Strengthen, Automate, and Scale Modern Workloads with Red Hat & NGINX
Secure, Strengthen, Automate, and Scale Modern Workloads with Red Hat & NGINX
 

Similar a Study Notes - Using an API Gateway

Similar a Study Notes - Using an API Gateway (20)

Comparison of Current Service Mesh Architectures
Comparison of Current Service Mesh ArchitecturesComparison of Current Service Mesh Architectures
Comparison of Current Service Mesh Architectures
 
WEB API Gateway
WEB API GatewayWEB API Gateway
WEB API Gateway
 
Intro to Microservices Architecture
Intro to Microservices ArchitectureIntro to Microservices Architecture
Intro to Microservices Architecture
 
Microservices
MicroservicesMicroservices
Microservices
 
Over view of software artitecture
Over view of software artitectureOver view of software artitecture
Over view of software artitecture
 
IBM API Connect Deployment `Good Practices - IBM Think 2018
IBM API Connect Deployment `Good Practices - IBM Think 2018IBM API Connect Deployment `Good Practices - IBM Think 2018
IBM API Connect Deployment `Good Practices - IBM Think 2018
 
Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019Istio Triangle Kubernetes Meetup Aug 2019
Istio Triangle Kubernetes Meetup Aug 2019
 
Microservices architecture
Microservices architectureMicroservices architecture
Microservices architecture
 
Do You Need A Service Mesh?
Do You Need A Service Mesh?Do You Need A Service Mesh?
Do You Need A Service Mesh?
 
Arsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry SusantoArsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry Susanto
 
APIGATEWAY in Microservices
APIGATEWAY in MicroservicesAPIGATEWAY in Microservices
APIGATEWAY in Microservices
 
Microservice architecture-api-gateway-considerations
Microservice architecture-api-gateway-considerationsMicroservice architecture-api-gateway-considerations
Microservice architecture-api-gateway-considerations
 
Acme Freight: Developing Microservices and APIs on Bluemix
Acme Freight: Developing Microservices and APIs on BluemixAcme Freight: Developing Microservices and APIs on Bluemix
Acme Freight: Developing Microservices and APIs on Bluemix
 
API Gateway How-To: The Many Ways to Apply the Gateway Pattern
API Gateway How-To: The Many Ways to Apply the Gateway PatternAPI Gateway How-To: The Many Ways to Apply the Gateway Pattern
API Gateway How-To: The Many Ways to Apply the Gateway Pattern
 
MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...
MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...
MuleSoft Surat Meetup#43 - Combine Service Mesh With Anypoint API Management ...
 
API Management within a Microservice Architecture
API Management within a Microservice ArchitectureAPI Management within a Microservice Architecture
API Management within a Microservice Architecture
 
API Management Within a Microservices Architecture
API Management Within a Microservices Architecture API Management Within a Microservices Architecture
API Management Within a Microservices Architecture
 
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
[APIdays Paris 2019] API Management in Service Mesh Using Istio and WSO2 API ...
 
Microservices and Deployment Methodologies
Microservices and Deployment MethodologiesMicroservices and Deployment Methodologies
Microservices and Deployment Methodologies
 
Uncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdfUncover the Flex Gateway with a Demonstration (1).pdf
Uncover the Flex Gateway with a Demonstration (1).pdf
 

Más de Rick Hwang

導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環
Rick Hwang
 

Más de Rick Hwang (20)

在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生在生命轉彎的地方 - 從軟體開發職涯,探索人生
在生命轉彎的地方 - 從軟體開發職涯,探索人生
 
20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生20230829 - 探索職涯,複利人生
20230829 - 探索職涯,複利人生
 
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會2023 08 - SRE 實踐與開發平台指南 - 書友見面會
2023 08 - SRE 實踐與開發平台指南 - 書友見面會
 
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
20230215 - 凝聚團隊共識的溝通方法 (Effective Team Communication)
 
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
軟體測試實務新書發表會 - 從品質與測試,讓軟體再次偉大
 
CH02 API Governance
CH02 API Governance CH02 API Governance
CH02 API Governance
 
Chapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdfChapter 8. Partial updates and retrievals.pdf
Chapter 8. Partial updates and retrievals.pdf
 
Ch09 Custom Methods
Ch09 Custom MethodsCh09 Custom Methods
Ch09 Custom Methods
 
AWS Career Exploration Day
AWS Career Exploration DayAWS Career Exploration Day
AWS Career Exploration Day
 
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
從理想、到現實的距離,開啟品味軟體測試之路 - 台灣軟體工程協會 (20220813)
 
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
SRE Conf 2022 - 91APP 在 AWS 上的 SRE 實踐之路
 
導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環 導讀持續交付 2.0 - CH02 價值探索環
導讀持續交付 2.0 - CH02 價值探索環
 
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
2020 AWS Summit - 如何有效管理 AWS 的成本結構與系統架構
 
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
災難演練 @ AWS 實戰分享 (Using AWS for Disaster Recovery)
 
Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214Software Development Process v1.5 - 20121214
Software Development Process v1.5 - 20121214
 
第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路第三章 建立良好的人際關係網路
第三章 建立良好的人際關係網路
 
Wiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected MindWiki in Teamroom - Connected Mind
Wiki in Teamroom - Connected Mind
 
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合導讀持續交付 2.0 - 談當代軟體交付之虛實融合
導讀持續交付 2.0 - 談當代軟體交付之虛實融合
 
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018從緊急事件  談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
從緊急事件 談 SRE 應變能力的培養 - DevOpsDays Taipei 2018
 
Continuous Delivery - Opening
Continuous Delivery - OpeningContinuous Delivery - Opening
Continuous Delivery - Opening
 

Último

Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
amitlee9823
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
amitlee9823
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
amitlee9823
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
karishmasinghjnh
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
amitlee9823
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 

Último (20)

BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Thane West Call On 9920725232 With Body to body massage...
 
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
Escorts Service Kumaraswamy Layout ☎ 7737669865☎ Book Your One night Stand (B...
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men  🔝Mathura🔝   Escorts...
➥🔝 7737669865 🔝▻ Mathura Call-girls in Women Seeking Men 🔝Mathura🔝 Escorts...
 
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night StandCall Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Attibele ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 

Study Notes - Using an API Gateway

  • 1. Chapter 2 Using an API Gateway Designing and Deploying Microservices 1 by Chris Richardson
  • 2. 2
  • 3. 1. Number of items in the shopping cart 2. Order history 3. Customer reviews 4. Low inventory warning 5. Shipping options 6. Various recommendations, including other products this product is frequently bought with, other products bought by customers who bought this product, and other products viewed by customers who bought this product 7. Alternative purchasing options 3
  • 4. GET api.company.com/productdetails/productId Monolithic application architecture A load balancer routes the request to one of several identical application instances. The application then queries various database tables and return the response to the client 4
  • 5. Microservices Architecture ● Shopping Cart Service – Number of items in the shopping cart ● Order Service – Order history ● Catalog Service – Basic product information, such as product name, image, and price ● Review Service – Customer reviews ● Inventory Service – Low inventory warning ● Shipping Service – Shipping options, deadlines, and costs, drawn separately from the shipping provider’s API ● Recommendation Service(s) – Suggested items 5
  • 6. 6
  • 10. The First Problem is the mismatch between the needs of the client and the fine-grained APIs exposed by each of the microservices. 10
  • 11. The First Problem 1. The client in this example has to make seven separate requests. ○ For example, Amazon describes how hundreds of services are involved in rendering their product page. 2. Too inefficient over the public Internet 11 一個頁面要七個請求 一個頁面要二十個請求 一個頁面要一百個請求
  • 12. The Second Problem is the client directly calling the microservices is that some might use protocols that are not web-friendly. 12
  • 13. 1. One service might use Thrift binary RPC while another service might use the AMQP messaging protocol. 2. An application should use protocols such as HTTP and WebSocket outside of the firewall. The Second Problem Apache Thrift 13
  • 14. The Third Problem is it makes it difficult to refactor the microservices. 14
  • 15. The Thrid Problem 1. Over time we might want to change how the system is partitioned into services. For example, we might merge two services or split a service into two or more services. 2. The clients communicate directly with the services, then performing this kind of refactoring can be extremely difficult. 15
  • 16. Direct Client-to-Microservice Communication 1. fine-grained APIs exposed 2. protocols are not web-friendly. 3. difficult to refactor 16
  • 17. 17
  • 18. Using an API Gateway 18
  • 19. What is an API Gateway? ● Single entry point into the system ● similar to Facade pattern from OOD. ● other responsibilities such as authentication, monitoring, load balancing, caching, request shaping and management, and static response handling 19
  • 21. Amazon API Gateway Single Entry Point 21 Overview API Gateway
  • 22. Microservices on AWS (AWS Whitepaper, PDF) 22
  • 26. 26
  • 27. The API Gateway is responsible for 1. request routing: routes requests to the appropriate microservice. 2. composition: The API Gateway will often handle a request by invoking multiple microservices and aggregating the results 3. protocol translation: It can translate between web protocols such as HTTP and WebSocket and web-unfriendly protocols that are used internally. 27
  • 28. API Composition https://microservices.io/patterns/data/api-composition.html 28 1. a mobile client to retrieve all of the product details with a single request. 2. The API Gateway handles the request by invoking the various services – product information, recommendations, reviews, etc – and combining the results
  • 29. 1. The Netflix streaming service is available on hundreds of different kinds of devices including televisions, set-top boxes, smartphones, gaming systems, tablets, etc. 2. provide a one-size-fits-all API for their streaming service. 3. they use an API Gateway that provides an API tailored for each device by running device-specific adapter code. An adapter typically handles each request by invoking, on average, six to seven backend services. Example: Nextflix API Gateway 29
  • 30. Benefits and Drawbacks of an API Gateway 30
  • 31. Benefits ● A major bene t of using an API Gateway is that it encapsulates the internal structure of the application. ● The API Gateway provides each kind of client with a specific API. This reduces the number of round trips between the client and application. It also simplifies the client code. 31
  • 32. Drawbacks ● It is yet another highly available component that must be developed, deployed, and managed. ● There is also a risk that the API Gateway becomes a development bottleneck. 32
  • 33. Notes ● It is important that the process for updating the API Gateway be as lightweight as possible. (Deployment and Operational) ● Despite these drawbacks, however, for most real-world applications it makes sense to use an API Gateway. 33
  • 34. 34
  • 35. Implementing an API Gateway (賣產品) 35
  • 36. Performance and Scalability ● Only a handful of companies operate at the scale of Netflix and need to handle billions of requests per day. ● It makes sense, therefore, to build the API Gateway on a platform that supports asynchronous, non-blocking I/O. ● On the JVM you can use one of the NIO-based frameworks such Netty, Vertx, Spring Reactor, or JBoss Undertow. One popular non-JVM option is Node.js. ● NGINX Plus o ers a mature, scalable, high-performance web server and reverse proxy that is easily deployed, configured, and programmed. 36
  • 37. 37 https://microservices.io/patterns/data/api-composition.html Authencation before Validation the request using the traditional async callback approach quickly leads you to callback hell.
  • 38. Using a Reactive Programming Model ● CompletableFuture in Java 8 ● Promise in JavaScript ● Reactive Extensions (also called Rx or ReactiveX), in Microsoft.NET Platform 38
  • 39. Service Invocation ● A microservices-based application is a distributed system and must use an inter-process communication (IPC, Chapter 3) mechanism. ○ One option is to use an asynchronous, messaging-based mechanism. Some implementations use a message broker such as JMS or AMQP. Others, such as Zeromq, are brokerless and the services communicate directly. ○ The other style of inter-process communication is a synchronous mechanism such as HTTP or Thrift. ● Consequently, the API Gateway will need to support a variety of communication mechanisms. 39
  • 40. Service Discovery ● The API Gateway needs to know the location (IP address and port) of each microservice with which it communicates. ● in a modern, cloud-based microservices application, finding the needed locations is a non-trivial problem. ● determining the location of an application service is not so easy, because of autoscaling and upgrades. ● service discovery mechanism: either server-side discovery or client-side discovery Chapter 4 40
  • 41. Amazon API Gateway Single Entry Point 41Overview API Gateway
  • 42. Resource Discovery on AWS 42 ● Security Groups ● IAM Roles ● Resource Tags ● AWS SDK / CLI Ops as Code with AWS CLI TAG="ops:status" VALUE="retired" # 找出標記 retire 的機器 aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --filters Name=tag:$TAG,Values=$VALUE --output text | while IFS= read -r item do # 把 termination protection 關掉 aws ec2 modify-instance-attribute --instance-id $item --no-disable-api-termination # terminate EC2 instance aws ec2 terminate-instances --instance-ids $item done
  • 43. Handling Partial Failures ● This issue arises in all distributed systems whenever one service calls another service that is either responding slowly or is unavailable. ● For example, if the recommendation service is unresponsive in the product details scenario, the API Gateway should return the rest of the product details to the client since they are still useful to the user. ● The API Gateway could also return cached data if that is available. 43
  • 44. Netflix Hystrix (豪豬) ● Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable. ● implement circuit breaker pattern ● If the error rate for a service exceeds a specified threshold, Hystrix trips the circuit breaker and all requests will fail immediately for a specified period of time. (service 的 error rate 超過指定的臨界 值,Hystrix 跳開斷路器,在一段時間之 內立即中短所有的請求。 ) ● JVM base. 44
  • 45. 補充:Service Mesh ● 一種基礎架構 (infrastructure layer) 的服務,負責處理的是 Service 跟 Service 之間通訊的安全、可靠、速度。 ● 現代網路的基礎協議是 TCP/IP,Microservice 的通訊就是 Service Mesh 45
  • 48. 48 1. makes sense to implement an API Gateway which acts as a single entry point into a system 2. responsible for request routing, composition, and protocol translation 3. provides each of the application’s clients with a custom API. 4. mask failures in the backend services by returning cached or default data
  • 51. Reference ● Microservices.io ● Production-Ready Microservices (Free, 120+) ● Building Microservices ● Microservice Patterns (Manning) - MEAP ● Microservices on AWS (AWS Whitepaper, PDF) ● AWS re:Invent 2017: Building Microservice on AWS ● AWS re:Invent 2016: From Monolithic to Microservices: Evolving Architecture Patterns 51