SlideShare a Scribd company logo
Be a Microservices Hero | MesosCon’16
Dragos Dascalita Haut | Project Lead | Adobe I/O
Adobe I/O provides the definitive destination for Developers looking to
learn about, engage with and integrate Adobe cloud, mobile, and web
technologies.
Adobe Creative Cloud Apps
A CreativeCloud Microservice: Content-Aware Fill
A CreativeCloud Microservice: send to Photoshop from the mobile device
Focus of this presentation:
§  How to make it simple and consistent for developers to consume APIs
§  How to make it straight forward to publish APIs
There are 2 players in Microservices
There are common aspects surrounding an API
There are common aspects surrounding an API
There are common aspects surrounding an API
There are common aspects surrounding an API
API Management
API Management
api1 api2
Adobe I/O & Apache Mesos
Fill the API Management gap in Apache Mesos
by sharing the technology behind Adobe I/O
and develop it further with the community.
GOAL
§  Make it simple and consistent for developers to consume APIs
§  … and straight forward to publish APIs
API GATEWAY : The Adobe I/O Engine
•  OPEN SOURCE:
•  https://github.com/adobe-apiplatform/apigateway
•  FEATURES:
•  API Façade - to build a unified API from mutiple microservices
•  Controls Access by validating requests
•  Prevents Attacks through Throttling and Rate Limiting rules
•  Provides Analytics based on usage data
•  OOTB Service Discovery using Marathon and Mesos
•  With hooks for other service discovery implementations
API GATEWAY : The Adobe I/O Engine
•  FEATURES THE API GATEWAY SHOULD AVOID:
•  Payload transformation
•  Any other business logic particular to the domain of an API
DESIGN PRINCIPLES
Simple
Scalable
Secure
Super fast
API GATEWAY : The Adobe I/O Engine
OPENRESTY
•  Nginx Lua Module
•  Nginx Redis
•  Headers more
•  Set misc
•  LuaJIT
•  ….
API Gateway Modules
•  Request Validation
•  Throttling & Rate Limiting
•  HTTP Logger
NGINX
•  Upstream
•  HTTP Proxy
•  PCRE
•  SSL
•  ….
API GATEWAY : " …TAKE ONE OF THE MOST POPULAR WEB SERVER AND
ADD API GATEWAY CAPABILITIES TO IT…"
{
"id": "api-gateway",
"container": {
"type": "DOCKER",
"docker": {
"image": "adobeapiplatform/apigateway:throttling",
"forcePullImage": true,
"network": "HOST"
}
},
"cpus": 4,
"mem": 4028.0,
"env": { "MARATHON_HOST": "http://<marathon_host>" },
"acceptedResourceRoles": ["slave_public"],
"constraints": [ [ "hostname", "UNIQUE" ] ],
"ports": [ 80 ],
"instances": 1
}
curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '
API GATEWAY : Deployment with Marathon
API GATEWAY : Deployment with Marathon
{
"id": "api-gateway",
"container": {
"type": "DOCKER",
"docker": {
"image": "apiplatform/apigateway:latest",
"forcePullImage": true,
"network": "HOST"
}
},
"cpus": 4,
"mem": 4028.0,
"env": { "MARATHON_HOST": "http://<marathon_host>" },
"acceptedResourceRoles": ["slave_public"],
"constraints": [ [ "hostname", "UNIQUE" ] ],
"ports": [ 80 ],
"instances": 1,
<health_check_block>
}
curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '
Optionally you can include health-check
"healthChecks": [

{

"protocol": "HTTP",

"portIndex": 0,

"path": "/health-check",

"gracePeriodSeconds": 3,

"intervalSeconds": 10,

"timeoutSeconds": 10

}

]
server {
listen 80;
server_name hello-world.gw.mesosconference.org;
location / {
# -------------------------------------------------
# Specify what to validate for this location
# -------------------------------------------------
set $validate_api_key on;
set $validate_oauth_token on;
set $validate_user_profile on;
set $validate_service_plan on;
...
access_by_lua "ngx.apiGateway.validation.validateRequest()";
# -------------------------------------------------
# Proxy the request to the actual microservice
# -------------------------------------------------
proxy_pass http://hello-world;
}
}
API GATEWAY : Simple Service Definition to validate requests
server {
listen 80;
server_name hello-world.api.mesoscon.org;
location / {
# -------------------------------------------------
# Specify what to validate for this location
# -------------------------------------------------
set $validate_api_key on;
set $validate_oauth_token on;
set $validate_user_profile on;
set $validate_service_plan on;
...
access_by_lua "ngx.apiGateway.validation.validateRequest()";
# -------------------------------------------------
# Proxy the request to the actual microservice
# -------------------------------------------------
proxy_pass http://hello-world;
}
}
API GATEWAY : Routing is done based on Service Discovery
...
upstream hello-world {
# --------------------------------
# Specify the list of backends
# where hello-world microservice
# is running
# --------------------------------
server 10.0.0.7:13780;
server 10.0.0.8:11900;
...
}
server {
listen 80;
server_name hello-world.api.mesoscon.org;
location / {
# -------------------------------------------------
# Specify what to validate for this location
# -------------------------------------------------
set $validate_api_key on;
set $validate_oauth_token on;
set $validate_user_profile on;
set $validate_service_plan on;
...
access_by_lua "ngx.apiGateway.validation.validateRequest()";
# -------------------------------------------------
# Proxy the request to the actual microservice
# -------------------------------------------------
proxy_pass http://hello-world;
}
}
...
upstream hello-world {
# --------------------------------
# Specify the list of backends
# where hello-world microservice
# is running
# --------------------------------
server 10.0.0.7:13780;
server 10.0.0.8:11900;
...
}
SERVICE DEFINITION vs SERVICE DISCOVERY
server {
listen 80;
server_name hello-world.api.mesoscon.org;
location / {
# -------------------------------------------------
# Specify what to validate for this location
# -------------------------------------------------
set $validate_api_key on;
set $validate_oauth_token on;
set $validate_user_profile on;
set $validate_service_plan on;
...
access_by_lua "ngx.apiGateway.validation.validateRequest()";
# -------------------------------------------------
# Proxy the request to the actual microservice
# -------------------------------------------------
proxy_pass http://hello-world;
}
}
...
upstream hello-world {
# --------------------------------
# Specify the list of backends
# where hello-world microservice
# is running
# --------------------------------
server 10.0.0.7:13780;
server 10.0.0.8:11900;
...
}
SERVICE DEFINITION vs SERVICE DISCOVERY
•  Demo
curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '
{
"id": "hello-world",
"container": {
"type": "DOCKER",
"docker": {
"image": "adobeapiplatform/echo-microservice:latest",
"forcePullImage": false,
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 8080,
"hostPort": 0,
"protocol": "tcp"
}
]
}
},
"cpus": 0.5,
"mem": 1024.0,
"ports": [ 0 ],
"instances": 1
}'
DEPLOY THE SAMPLE hello-world MICROSERVICE :
… WITH 2 SIMPLE ENDPOINTS
curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '
{
"id": "api-gateway-redis",
"container": {
"type": "DOCKER",
"docker": {
"image": "redis:latest",
"forcePullImage": true,
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 6379,
"hostPort": 0,
"protocol": "tcp"
}
]
}
},
"cpus": 0.5,
"mem": 1024.0,
"constraints": [ [ "hostname", "UNIQUE" ] ],
"ports": [ 0 ],
"instances": 1
}'
API GATEWAY : API KEY Management with Redis
set $marathon_app_name hello-world;
location / {
…
# identify the service

set $service_id $marathon_app_name;



# READ THE API KEY
# either from the query string or from the "X-Api-Key" header

set $api_key $arg_api_key;

set_if_empty $api_key $http_x_api_key;



# add the api-key validator

set $validate_api_key on;



# validate request

access_by_lua "ngx.apiGateway.validation.validateRequest()";
proxy_pass http://$marathon_app_name;
Create a new Vhost for server_name ~hello-world.api.(?<domain>.+);
API GATEWAY : API KEY Management with Redis
Protecting a service with API-KEY Validation
# ADD an API-KEY for the HELLO-WORLD service
# NOTE: this API SHOULD not be exposed publicly
curl -X POST "http://api-gateway.${API_DOMAIN}/cache/api_key?key=key-1&
app_name=demo-app&
service_id=hello-world&
service_name=hello-world&
consumer_org_name=demo-consumer"
# update hello-world microservice to require an API-KEY
curl "http://hello-world.${API_DOMAIN}/hello"
# {"error_code":"403000","message":"Api Key is required"}
# make another call including the api-key
curl "http://hello-world.${API_DOMAIN}/hello" -H "X-Api-Key:key-1"
API GATEWAY : API KEY Management with Redis
Create a new API-KEY and save it into Redis cache
•  Demo: Throttling / Rate Limiting
THROTTLING: Installing the Microservice
curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data '
{
"id": "cell-os/gateway-tracking-service",
"container": {
"type": "DOCKER",
"docker": {
"image": "adobeapiplatform/gateway-tracking-service:latest",
"forcePullImage": false,
"network": "BRIDGE",
"portMappings": [ {"containerPort": 8080, "hostPort": 0, "protocol": "tcp"} ]
}
},
"env": {
"mesos.api.endpoint":"http://<marathon-host>/v2/apps/cell-os/api-gateway/tasks",
"spring.profiles.active":"mesos-cluster",
"gw.http.port":"5000",
"zmq.port":"6001",
"logging.level.com.adobe.api.platform.gwts.metrics.MetricsService":"WARN",
"redis.host":"<redis-host>",
"redis.port":"<redis_port>"
},
"cpus": 2,
"mem": 4096.0,
"ports": [ 0 ],
"instances": 1
}'
API GATEWAY : Adding a new throttling policy
curl -i -X POST "http://cell-os_gateway-tracking-service.<domain>/api/policies/throttling"
-H "Content-Type:application/json" -H "X-AMS-Policy-Type:THROTTLING_POLICY" --data '
[{
"id": "2",
"softLimit": 3,
"maxDelayPeriod": 4,
"hardLimit": 5,
"timeUnit": "SECONDS",
"span": 30,
"lastModified": 1438019079000,
"domain": {
"$api_key": "key-1"
}
}]'
A Low Water Mark after which the Gateway DELAYS requests
A High Water Mark after which the Gateway BLOCKS requests
Limits are enforced on a 30s time window
This policy is enforced only on requests with api_key=key-1
API GATEWAY : Listing existing throttling policies
curl "http://cell-os_gateway-tracking-service.<domain>/api/policies/throttling"
[{
id: 2,
lastModified: 1438019079000,
domain: {
$api_key: "key-1"
},
softLimit: 5,
hardLimit: 9,
timeUnit: "SECONDS",
span: 30,
maxDelayPeriod: 3
}]
•  Demo: Analytics
Key Takeaways
1.  Think holistically at microservices
2.  "Less is more." "Does my microservice really need to care about ..."
•  Identify Provider, Access Control, Throttling
3.  Think about integrating a microservice API Gateway into your
Mesos clusters
•  Consider using a proven solution used by Adobe I/O
https://github.com/adobe-apiplatform/apigateway
Resources:
https://github.com/adobe-apiplatform/apigateway
http://adobe.io
MesosCon - Be a microservices hero

More Related Content

What's hot

Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
Chef
 

What's hot (20)

Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011Plack basics for Perl websites - YAPC::EU 2011
Plack basics for Perl websites - YAPC::EU 2011
 
Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5Environments - Fundamentals Webinar Series Week 5
Environments - Fundamentals Webinar Series Week 5
 
RESTful Web Applications with Apache Sling
RESTful Web Applications with Apache SlingRESTful Web Applications with Apache Sling
RESTful Web Applications with Apache Sling
 
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4Common configuration with Data Bags - Fundamentals Webinar Series Part 4
Common configuration with Data Bags - Fundamentals Webinar Series Part 4
 
Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!Apache and PHP: Why httpd.conf is your new BFF!
Apache and PHP: Why httpd.conf is your new BFF!
 
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
 
Node.js Workshop
Node.js WorkshopNode.js Workshop
Node.js Workshop
 
RESTful modules in zf2
RESTful modules in zf2RESTful modules in zf2
RESTful modules in zf2
 
Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.Best Practices for Architecting a Pragmatic Web API.
Best Practices for Architecting a Pragmatic Web API.
 
Deploying configurable frontend web application containers
Deploying configurable frontend web application containersDeploying configurable frontend web application containers
Deploying configurable frontend web application containers
 
Jcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applicationsJcon 2017 How to use Swagger to develop REST applications
Jcon 2017 How to use Swagger to develop REST applications
 
Modern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on RailsModern JavaScript, without giving up on Rails
Modern JavaScript, without giving up on Rails
 
Composable and streamable Play apps
Composable and streamable Play appsComposable and streamable Play apps
Composable and streamable Play apps
 
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
MongoDB World 2018: Tutorial - Got Dibs? Building a Real-Time Bidding App wit...
 
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Servicesewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
ewd-qoper8-vistarpc: Exposing VistA's RPCs as REST Services
 
MuleSoft Integration with AWS Cognito Client Credentials and Mule JWT Validat...
MuleSoft Integration with AWS Cognito Client Credentials and Mule JWT Validat...MuleSoft Integration with AWS Cognito Client Credentials and Mule JWT Validat...
MuleSoft Integration with AWS Cognito Client Credentials and Mule JWT Validat...
 
Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...Maxim Salnikov - Service Worker: taking the best from the past experience for...
Maxim Salnikov - Service Worker: taking the best from the past experience for...
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
OSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian SchneiderOSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian Schneider
 
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...DEVNET-2002	Coding 201: Coding Skills 201: Going Further with REST and Python...
DEVNET-2002 Coding 201: Coding Skills 201: Going Further with REST and Python...
 

Similar to MesosCon - Be a microservices hero

Similar to MesosCon - Be a microservices hero (20)

ContainerCon 2015 - Be a Microservices Hero
ContainerCon 2015 - Be a Microservices HeroContainerCon 2015 - Be a Microservices Hero
ContainerCon 2015 - Be a Microservices Hero
 
Be a microservices hero
Be a microservices heroBe a microservices hero
Be a microservices hero
 
Consul 1.6: Layer 7 Traffic Management and Mesh Gateways
Consul 1.6: Layer 7 Traffic Management and Mesh GatewaysConsul 1.6: Layer 7 Traffic Management and Mesh Gateways
Consul 1.6: Layer 7 Traffic Management and Mesh Gateways
 
Consull7 webinar hasicorp
Consull7 webinar hasicorpConsull7 webinar hasicorp
Consull7 webinar hasicorp
 
how to use openstack api
how to use openstack apihow to use openstack api
how to use openstack api
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
 
AWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and JavaAWS Lambda with Serverless Framework and Java
AWS Lambda with Serverless Framework and Java
 
Containers as a Service with Docker
Containers as a Service with DockerContainers as a Service with Docker
Containers as a Service with Docker
 
Docker Container As A Service - March 2016
Docker Container As A Service - March 2016Docker Container As A Service - March 2016
Docker Container As A Service - March 2016
 
Docker In Bank Unrated
Docker In Bank UnratedDocker In Bank Unrated
Docker In Bank Unrated
 
The Challenges of Becoming Cloud Native
The Challenges of Becoming Cloud NativeThe Challenges of Becoming Cloud Native
The Challenges of Becoming Cloud Native
 
Making a small QA system with Docker
Making a small QA system with DockerMaking a small QA system with Docker
Making a small QA system with Docker
 
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
 
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API GatewayMigrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
Migrate your Existing Express Apps to AWS Lambda and Amazon API Gateway
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
Building a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger HuntBuilding a REST API Microservice for the DevNet API Scavenger Hunt
Building a REST API Microservice for the DevNet API Scavenger Hunt
 
StrongLoop Overview
StrongLoop OverviewStrongLoop Overview
StrongLoop Overview
 
Working with PowerVC via its REST APIs
Working with PowerVC via its REST APIsWorking with PowerVC via its REST APIs
Working with PowerVC via its REST APIs
 
(ARC401) Cloud First: New Architecture for New Infrastructure
(ARC401) Cloud First: New Architecture for New Infrastructure(ARC401) Cloud First: New Architecture for New Infrastructure
(ARC401) Cloud First: New Architecture for New Infrastructure
 
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
Fully Automate Application Delivery with Puppet and F5 - PuppetConf 2014
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
Atif Razi
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
Kamal Acharya
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
Kamal Acharya
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 

Recently uploaded (20)

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical SolutionsRS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
RS Khurmi Machine Design Clutch and Brake Exercise Numerical Solutions
 
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptxCloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
Cloud-Computing_CSE311_Computer-Networking CSE GUB BD - Shahidul.pptx
 
Hall booking system project report .pdf
Hall booking system project report  .pdfHall booking system project report  .pdf
Hall booking system project report .pdf
 
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-5 Notes for II-II Mechanical Engineering
 
Architectural Portfolio Sean Lockwood
Architectural Portfolio Sean LockwoodArchitectural Portfolio Sean Lockwood
Architectural Portfolio Sean Lockwood
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
NO1 Pandit Amil Baba In Bahawalpur, Sargodha, Sialkot, Sheikhupura, Rahim Yar...
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
Arduino based vehicle speed tracker project
Arduino based vehicle speed tracker projectArduino based vehicle speed tracker project
Arduino based vehicle speed tracker project
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdfDanfoss NeoCharge Technology -A Revolution in 2024.pdf
Danfoss NeoCharge Technology -A Revolution in 2024.pdf
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdfA CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
A CASE STUDY ON ONLINE TICKET BOOKING SYSTEM PROJECT.pdf
 
Online resume builder management system project report.pdf
Online resume builder management system project report.pdfOnline resume builder management system project report.pdf
Online resume builder management system project report.pdf
 
fundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projectionfundamentals of drawing and isometric and orthographic projection
fundamentals of drawing and isometric and orthographic projection
 
Explosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdfExplosives Industry manufacturing process.pdf
Explosives Industry manufacturing process.pdf
 
Fruit shop management system project report.pdf
Fruit shop management system project report.pdfFruit shop management system project report.pdf
Fruit shop management system project report.pdf
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 

MesosCon - Be a microservices hero

  • 1. Be a Microservices Hero | MesosCon’16 Dragos Dascalita Haut | Project Lead | Adobe I/O
  • 2. Adobe I/O provides the definitive destination for Developers looking to learn about, engage with and integrate Adobe cloud, mobile, and web technologies.
  • 4. A CreativeCloud Microservice: Content-Aware Fill
  • 5. A CreativeCloud Microservice: send to Photoshop from the mobile device
  • 6. Focus of this presentation: §  How to make it simple and consistent for developers to consume APIs §  How to make it straight forward to publish APIs
  • 7. There are 2 players in Microservices
  • 8. There are common aspects surrounding an API
  • 9. There are common aspects surrounding an API
  • 10. There are common aspects surrounding an API
  • 11. There are common aspects surrounding an API
  • 12.
  • 13.
  • 17.
  • 18.
  • 19. Adobe I/O & Apache Mesos
  • 20. Fill the API Management gap in Apache Mesos by sharing the technology behind Adobe I/O and develop it further with the community.
  • 21. GOAL §  Make it simple and consistent for developers to consume APIs §  … and straight forward to publish APIs
  • 22. API GATEWAY : The Adobe I/O Engine •  OPEN SOURCE: •  https://github.com/adobe-apiplatform/apigateway •  FEATURES: •  API Façade - to build a unified API from mutiple microservices •  Controls Access by validating requests •  Prevents Attacks through Throttling and Rate Limiting rules •  Provides Analytics based on usage data •  OOTB Service Discovery using Marathon and Mesos •  With hooks for other service discovery implementations
  • 23. API GATEWAY : The Adobe I/O Engine •  FEATURES THE API GATEWAY SHOULD AVOID: •  Payload transformation •  Any other business logic particular to the domain of an API
  • 25. OPENRESTY •  Nginx Lua Module •  Nginx Redis •  Headers more •  Set misc •  LuaJIT •  …. API Gateway Modules •  Request Validation •  Throttling & Rate Limiting •  HTTP Logger NGINX •  Upstream •  HTTP Proxy •  PCRE •  SSL •  …. API GATEWAY : " …TAKE ONE OF THE MOST POPULAR WEB SERVER AND ADD API GATEWAY CAPABILITIES TO IT…"
  • 26. { "id": "api-gateway", "container": { "type": "DOCKER", "docker": { "image": "adobeapiplatform/apigateway:throttling", "forcePullImage": true, "network": "HOST" } }, "cpus": 4, "mem": 4028.0, "env": { "MARATHON_HOST": "http://<marathon_host>" }, "acceptedResourceRoles": ["slave_public"], "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 80 ], "instances": 1 } curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' API GATEWAY : Deployment with Marathon
  • 27. API GATEWAY : Deployment with Marathon { "id": "api-gateway", "container": { "type": "DOCKER", "docker": { "image": "apiplatform/apigateway:latest", "forcePullImage": true, "network": "HOST" } }, "cpus": 4, "mem": 4028.0, "env": { "MARATHON_HOST": "http://<marathon_host>" }, "acceptedResourceRoles": ["slave_public"], "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 80 ], "instances": 1, <health_check_block> } curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' Optionally you can include health-check "healthChecks": [
 {
 "protocol": "HTTP",
 "portIndex": 0,
 "path": "/health-check",
 "gracePeriodSeconds": 3,
 "intervalSeconds": 10,
 "timeoutSeconds": 10
 }
 ]
  • 28. server { listen 80; server_name hello-world.gw.mesosconference.org; location / { # ------------------------------------------------- # Specify what to validate for this location # ------------------------------------------------- set $validate_api_key on; set $validate_oauth_token on; set $validate_user_profile on; set $validate_service_plan on; ... access_by_lua "ngx.apiGateway.validation.validateRequest()"; # ------------------------------------------------- # Proxy the request to the actual microservice # ------------------------------------------------- proxy_pass http://hello-world; } } API GATEWAY : Simple Service Definition to validate requests
  • 29. server { listen 80; server_name hello-world.api.mesoscon.org; location / { # ------------------------------------------------- # Specify what to validate for this location # ------------------------------------------------- set $validate_api_key on; set $validate_oauth_token on; set $validate_user_profile on; set $validate_service_plan on; ... access_by_lua "ngx.apiGateway.validation.validateRequest()"; # ------------------------------------------------- # Proxy the request to the actual microservice # ------------------------------------------------- proxy_pass http://hello-world; } } API GATEWAY : Routing is done based on Service Discovery ... upstream hello-world { # -------------------------------- # Specify the list of backends # where hello-world microservice # is running # -------------------------------- server 10.0.0.7:13780; server 10.0.0.8:11900; ... }
  • 30. server { listen 80; server_name hello-world.api.mesoscon.org; location / { # ------------------------------------------------- # Specify what to validate for this location # ------------------------------------------------- set $validate_api_key on; set $validate_oauth_token on; set $validate_user_profile on; set $validate_service_plan on; ... access_by_lua "ngx.apiGateway.validation.validateRequest()"; # ------------------------------------------------- # Proxy the request to the actual microservice # ------------------------------------------------- proxy_pass http://hello-world; } } ... upstream hello-world { # -------------------------------- # Specify the list of backends # where hello-world microservice # is running # -------------------------------- server 10.0.0.7:13780; server 10.0.0.8:11900; ... } SERVICE DEFINITION vs SERVICE DISCOVERY
  • 31. server { listen 80; server_name hello-world.api.mesoscon.org; location / { # ------------------------------------------------- # Specify what to validate for this location # ------------------------------------------------- set $validate_api_key on; set $validate_oauth_token on; set $validate_user_profile on; set $validate_service_plan on; ... access_by_lua "ngx.apiGateway.validation.validateRequest()"; # ------------------------------------------------- # Proxy the request to the actual microservice # ------------------------------------------------- proxy_pass http://hello-world; } } ... upstream hello-world { # -------------------------------- # Specify the list of backends # where hello-world microservice # is running # -------------------------------- server 10.0.0.7:13780; server 10.0.0.8:11900; ... } SERVICE DEFINITION vs SERVICE DISCOVERY
  • 33. curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "hello-world", "container": { "type": "DOCKER", "docker": { "image": "adobeapiplatform/echo-microservice:latest", "forcePullImage": false, "network": "BRIDGE", "portMappings": [ { "containerPort": 8080, "hostPort": 0, "protocol": "tcp" } ] } }, "cpus": 0.5, "mem": 1024.0, "ports": [ 0 ], "instances": 1 }' DEPLOY THE SAMPLE hello-world MICROSERVICE :
  • 34. … WITH 2 SIMPLE ENDPOINTS
  • 35. curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "api-gateway-redis", "container": { "type": "DOCKER", "docker": { "image": "redis:latest", "forcePullImage": true, "network": "BRIDGE", "portMappings": [ { "containerPort": 6379, "hostPort": 0, "protocol": "tcp" } ] } }, "cpus": 0.5, "mem": 1024.0, "constraints": [ [ "hostname", "UNIQUE" ] ], "ports": [ 0 ], "instances": 1 }' API GATEWAY : API KEY Management with Redis
  • 36. set $marathon_app_name hello-world; location / { … # identify the service
 set $service_id $marathon_app_name;
 
 # READ THE API KEY # either from the query string or from the "X-Api-Key" header
 set $api_key $arg_api_key;
 set_if_empty $api_key $http_x_api_key;
 
 # add the api-key validator
 set $validate_api_key on;
 
 # validate request
 access_by_lua "ngx.apiGateway.validation.validateRequest()"; proxy_pass http://$marathon_app_name; Create a new Vhost for server_name ~hello-world.api.(?<domain>.+); API GATEWAY : API KEY Management with Redis Protecting a service with API-KEY Validation
  • 37. # ADD an API-KEY for the HELLO-WORLD service # NOTE: this API SHOULD not be exposed publicly curl -X POST "http://api-gateway.${API_DOMAIN}/cache/api_key?key=key-1& app_name=demo-app& service_id=hello-world& service_name=hello-world& consumer_org_name=demo-consumer" # update hello-world microservice to require an API-KEY curl "http://hello-world.${API_DOMAIN}/hello" # {"error_code":"403000","message":"Api Key is required"} # make another call including the api-key curl "http://hello-world.${API_DOMAIN}/hello" -H "X-Api-Key:key-1" API GATEWAY : API KEY Management with Redis Create a new API-KEY and save it into Redis cache
  • 38. •  Demo: Throttling / Rate Limiting
  • 39. THROTTLING: Installing the Microservice curl -X POST -H "Content-Type:application/json" ${MARATHON_HOST}/v2/apps?force=true --data ' { "id": "cell-os/gateway-tracking-service", "container": { "type": "DOCKER", "docker": { "image": "adobeapiplatform/gateway-tracking-service:latest", "forcePullImage": false, "network": "BRIDGE", "portMappings": [ {"containerPort": 8080, "hostPort": 0, "protocol": "tcp"} ] } }, "env": { "mesos.api.endpoint":"http://<marathon-host>/v2/apps/cell-os/api-gateway/tasks", "spring.profiles.active":"mesos-cluster", "gw.http.port":"5000", "zmq.port":"6001", "logging.level.com.adobe.api.platform.gwts.metrics.MetricsService":"WARN", "redis.host":"<redis-host>", "redis.port":"<redis_port>" }, "cpus": 2, "mem": 4096.0, "ports": [ 0 ], "instances": 1 }'
  • 40. API GATEWAY : Adding a new throttling policy curl -i -X POST "http://cell-os_gateway-tracking-service.<domain>/api/policies/throttling" -H "Content-Type:application/json" -H "X-AMS-Policy-Type:THROTTLING_POLICY" --data ' [{ "id": "2", "softLimit": 3, "maxDelayPeriod": 4, "hardLimit": 5, "timeUnit": "SECONDS", "span": 30, "lastModified": 1438019079000, "domain": { "$api_key": "key-1" } }]' A Low Water Mark after which the Gateway DELAYS requests A High Water Mark after which the Gateway BLOCKS requests Limits are enforced on a 30s time window This policy is enforced only on requests with api_key=key-1
  • 41. API GATEWAY : Listing existing throttling policies curl "http://cell-os_gateway-tracking-service.<domain>/api/policies/throttling" [{ id: 2, lastModified: 1438019079000, domain: { $api_key: "key-1" }, softLimit: 5, hardLimit: 9, timeUnit: "SECONDS", span: 30, maxDelayPeriod: 3 }]
  • 43.
  • 44.
  • 45. Key Takeaways 1.  Think holistically at microservices 2.  "Less is more." "Does my microservice really need to care about ..." •  Identify Provider, Access Control, Throttling 3.  Think about integrating a microservice API Gateway into your Mesos clusters •  Consider using a proven solution used by Adobe I/O https://github.com/adobe-apiplatform/apigateway