Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Animesh Singh
STSM IBM Cloud Platform
Cloud Expo, Santa Clara, November 2016
@AnimeshSingh
How to build a Distributed Serv...
@AnimeshSingh
Cloud Computing Evolution
Bare Metal
IaaS
Container Orchestrators
PaaS
@AnimeshSingh
Problem: It’s expensive to scale microservices, even
on a PaaS
Explosion in number of
containers / processes...
@AnimeshSingh
Problem: the programming and cost model doesn’t
help
•  Continuous polling needed in the absence of an 

eve...
@AnimeshSingh
Bare Metal
IaaS
Container Orchestrators
PaaS
Enter Serverless!
Serverless
@AnimeshSingh
a cloud-native platform
for
short-running, stateless computation
and
event-driven applications
which
scales ...
@AnimeshSingh
Why is Serverless attractive?
7
Short answer:
Besides
a)  making app development & ops dramatically faster, ...
@AnimeshSingh
Key factors for infrastructure cost savings
Traditional models (CF,
containers, VMs)
Serverless
High Availab...
@AnimeshSingh
What is Serverless good for?
9
Introducing OpenWhisk,
a fabric and platform for
the serverless, event driven
programming model
@AnimeshSingh
What is OpenWhisk?
an open Beta offering in IBM’s Bluemix cloud
@AnimeshSingh
What is OpenWhisk?
an open-source project on github
@AnimeshSingh
Build your apps, your way.
Use a combination of the most prominent open-source compute
technologies to power...
@AnimeshSingh
What is OpenWhisk?
a distributed compute service to execute application logic in response
to events.
@AnimeshSingh
OpenWhisk: How does it work?
Incoming HTTP request, e.g. HTTP GET
openwhisk.ng.bluemix.net/api/v1/<namespace...
@AnimeshSingh
OpenWhisk: How does it work?
-  API Gateway takes care of…
-  security (authenticate, authorize, threat prot...
The OpenWhisk
programming model
What is OpenWhisk?
a high-level serverless programming model
Trigger
Rule
Action
Package
What is OpenWhisk?
a high-level serverless programming model
Trigger
Rule
Action
Package
language support to
encapsulate, ...
@AnimeshSingh
Trigger: A class of events that can happenT
Programming model
@AnimeshSingh
Actions: An event-handler, i.e. code that runs in response to an
event
A
Programming model
@AnimeshSingh
Programming model
Actions: Multi-runtime support, e.g. JavaScriptA
function	main(msg)	{	
	return	{	message:	...
@AnimeshSingh
Actions: Multi-runtime support, e.g. SwiftA
func	main(params:[String:Any])	->	[String:Any]	{		
	var	reply	=	...
@AnimeshSingh
Actions: In any other language by packaging with Docker
A
Programming model
@AnimeshSingh
Rules: An association of a trigger and an actionR
R := T A
Programming model
@AnimeshSingh
Actions: Can be chained to create sequences to increase
flexibility and foster reuse
A
AA
:= A1
+ A2
+ A3
AB...
@AnimeshSingh
Packages: A shared collection of triggers and actionsP
A
A read
write
T changes A translate A forecast
A pos...
OpenWhisk
backend architecture
@AnimeshSingh
github.com
openwhisk/openwhisk
!
!
!
!
core
runtime
CLIpackages
security
features
persistent
store
loggingmo...
@AnimeshSingh
Edge!
VM!
Edge!
VM!
!
Edge!
!
!
!
!
Edge!
VM!
Edge!
VM!
Master!
!
!
!
!
!
!
!
!
controller
Edge!
VM!
Edge!
V...
Why
Docker?
@AnimeshSingh
controller
invoker
Deploying and managing
traditional microservices
1
Why Docker?
@AnimeshSingh
Slave VM
Lightweight isolated execution environment
for arbitrary user code
action container
action containe...
@AnimeshSingh
Portable description of arbitrary
binary user actions (Dockerfile)
Docker file
3
Why Docker?
@AnimeshSingh
% wsk action invoke hello
in 8 easy steps
How it all works?
POST /api/v1/namespaces/myNamespace/actions/myAc...
36
Controller
…
Invoker InvokerInvoker
1!
2!
3,4!
5!
6!
7!
8!
OpenWhisk Topology
@AnimeshSingh
Cloudant
ELK-Stack
Controller
Integration
Service
…InvokerInvokerInvoker
Monitoring
OpenWhisk Topology in Bl...
@AnimeshSingh
OpenWhisk: Usage of Docker
•  Isolation of actions
•  Control over consumed resources of each container
38
A...
@AnimeshSingh
OpenWhisk: Container startup
39
Start container
docker run
Initialize
/init
Run
/run
cold container
@AnimeshSingh
Start container
docker run
Initialize
/init
Run
/run
OpenWhisk: Container startup
40
pre-warmed container
@AnimeshSingh
Start container
docker run
Initialize
/init
Run
/run
OpenWhisk: Container startup
41
warm container
@AnimeshSingh
OpenWhisk: Container startup optimization
•  Performance is king.
42
cold container pre-warmed container war...
IoT Usecase
Node-RED and MQTT
@AnimeshSingh
CLIENTS
BROKER
@AnimeshSinghSUBSCRIBE
PUBLISH
{…}
{…}
{…}
{…}
@AnimeshSingh
COMMERCIALOPEN-SOURCE
MOSQUITTO
MOSCA
ACTIVEMQ
RABBITMQ
MESSAGESIGHT
HIVEMQ
THINGMQ
CLOUDMQTT
MQTT Brokers
@AnimeshSingh
MQTT NODES IN NODE-RED
@AnimeshSingh
DEVICES NODE-RED
BROKER
@AnimeshSinghDEVICES
NODE-RED
BROKER
OpenWhisk Feeds
and creating MQTT feeds
@AnimeshSingh
Trigger
Action
Action
Action
push, fork, comment, ..
CUSTOM FEED EXAMPLE
@AnimeshSingh
anybody can create a Package with a feed
/whisk.system/github /mynamespace/github
MQTT feeds for OpenWhisk
•  Bridging MQTT messages to OpenWhisk Actions can be achieved by creating a new Feed provider. T...
MQTT feeds for OpenWhisk
•  This service provider is packaged using Docker.
•  Pushing this image into the IBM Containers ...
Registering Feeds
http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/
Node-RED for Serverless
OpenWhisk
@AnimeshSingh
Node-RED and OpenWhisk
•  Community effort to integrate with open tools: NodeRED
•  NodeRED is all about aut...
@AnimeshSingh
•  Use Node-RED to create Multi cloud Serveless Applications!
Use Node-RED to compose Serverless Application...
@AnimeshSingh
Devices
Node-RED & OpenWhisk
MQTT
Broker Trigger
Action
Action
Action
Bringing it all together – Serverless ...
Summary
@AnimeshSingh
What you learned today
•  We’re in the early days of an evolution that is empowering developers
to write clo...
@AnimeshSingh
Experiment with OpenWhisk on Bluemix
bit.ly/ow-bm
@AnimeshSingh
Join us to build a cloud native platform for the future!
OpenWhisk.org
dwopen.slack.com #openwhisk
bluemix.n...
Thank You
How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
Upcoming SlideShare
Loading in …5
×

How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

4,758 views

Published on

When people aren't talking about VMs and containers, they're talking about serverless architecture. Serverless is about no maintenance. It means you are not worried about low-level infrastructural and operational details. An event-driven serverless platform is a great use case for IoT.

In this session at @ThingsExpo, Animesh Singh, an STSM and Lead for IBM Cloud Platform and Infrastructure, detailed how to build a distributed serverless, polyglot, microservices framework using open source technologies like:

OpenWhisk: Open source distributed compute service to execute application logic in response to events

Docker: To run event driven actions 6. Ansible and BOSH: to deploy the serverless platform

MQTT: Messaging protocol for IoT

Node-RED: Tool to wire IoT together

Consul: Tool for service discovery and configuration. Consul is distributed, highly available, and extremely scalable.

Kafka: A high-throughput distributed messaging system.

StatsD/ELK/Graphite: For statistics, monitoring and logging

Published in: Software
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... 1.DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yxufevpm } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk

  1. 1. Animesh Singh STSM IBM Cloud Platform Cloud Expo, Santa Clara, November 2016 @AnimeshSingh How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
  2. 2. @AnimeshSingh Cloud Computing Evolution Bare Metal IaaS Container Orchestrators PaaS
  3. 3. @AnimeshSingh Problem: It’s expensive to scale microservices, even on a PaaS Explosion in number of containers / processes: 1.  Increase of infrastructure cost footprint 2.  Increase of operational management cost and complexity Region B Region A Break-down into microservices Make each micro service HA Protect against regional outages Monolithic application
  4. 4. @AnimeshSingh Problem: the programming and cost model doesn’t help •  Continuous polling needed in the absence of an 
 event driven programming model. •  Charged for resources, even when idle. •  Worries persist about capacity management. Swift Application Container VM CF 2 Polling 1b Request 1a
  5. 5. @AnimeshSingh Bare Metal IaaS Container Orchestrators PaaS Enter Serverless! Serverless
  6. 6. @AnimeshSingh a cloud-native platform for short-running, stateless computation and event-driven applications which scales up and down instantly and automatically and charges for actual usage at a millisecond granularity event handlersevents What is Serverless?
  7. 7. @AnimeshSingh Why is Serverless attractive? 7 Short answer: Besides a)  making app development & ops dramatically faster, cheaper, easier (but different J ), it b)  Drives infrastructure cost savings (yes – this has been true for most IT innovations over the last decades, while serverless potentially introduces another step-function change)
  8. 8. @AnimeshSingh Key factors for infrastructure cost savings Traditional models (CF, containers, VMs) Serverless High Availability At least 2-3 instances of everything No incremental infrastructure Multi-region deployment One deployment per region No incremental infrastructure Cover delta between short (<10s) load spikes and valleys (vs average) ~2x of average load No incremental infrastructure Example incremental costs 2 instances x 2 regions x 2 = 8x 1x 8
  9. 9. @AnimeshSingh What is Serverless good for? 9
  10. 10. Introducing OpenWhisk, a fabric and platform for the serverless, event driven programming model
  11. 11. @AnimeshSingh What is OpenWhisk? an open Beta offering in IBM’s Bluemix cloud
  12. 12. @AnimeshSingh What is OpenWhisk? an open-source project on github
  13. 13. @AnimeshSingh Build your apps, your way. Use a combination of the most prominent open-source compute technologies to power your apps. Then, let Bluemix handle the rest. Ease of getting startedFull stack Control FunctionsPaaSContainersIaaS What is OpenWhisk? another way to build apps….
  14. 14. @AnimeshSingh What is OpenWhisk? a distributed compute service to execute application logic in response to events.
  15. 15. @AnimeshSingh OpenWhisk: How does it work? Incoming HTTP request, e.g. HTTP GET openwhisk.ng.bluemix.net/api/v1/<namespace>/actions/getCustomers 1 Browser Mobile App Web App OpenWhisk 2 Invoke associated OpenWhisk action „getCustomers“ Swift! DockerJS! Python! Java*! Variety of languages * work in progress
  16. 16. @AnimeshSingh OpenWhisk: How does it work? -  API Gateway takes care of… -  security (authenticate, authorize, threat protect, validate) -  control (rate limiting, response caching) -  mediation -  parameter mapping -  schema validation -  … and supports e.g. different verbs (Get, Post, Put, Delete, …) Incoming HTTP request, e.g. HTTP GET api-gw.mybluemix.net/…/getCustomers 1 Browser Mobile App Web App APIGateway 2 OpenWhisk 3 Invoke associated OpenWhisk action „getCustomers“ Swift! DockerJS! Python! Java*! * work in progress Coming soon...
  17. 17. The OpenWhisk programming model
  18. 18. What is OpenWhisk? a high-level serverless programming model Trigger Rule Action Package
  19. 19. What is OpenWhisk? a high-level serverless programming model Trigger Rule Action Package language support to encapsulate, share, extend code first-class event-driven programming constructs first-class functions compose via sequences docker containers as actions all constructs first-class — powerful extensible language
  20. 20. @AnimeshSingh Trigger: A class of events that can happenT Programming model
  21. 21. @AnimeshSingh Actions: An event-handler, i.e. code that runs in response to an event A Programming model
  22. 22. @AnimeshSingh Programming model Actions: Multi-runtime support, e.g. JavaScriptA function main(msg) { return { message: 'Hello, ' + msg.name + ' from ' + msg.place }; };
  23. 23. @AnimeshSingh Actions: Multi-runtime support, e.g. SwiftA func main(params:[String:Any]) -> [String:Any] { var reply = [String:Any] () if let name = params[“name”] as? String { print(“Hello (name)”) reply[“msg”] = “Goodbye (name)” } return reply } Programming model
  24. 24. @AnimeshSingh Actions: In any other language by packaging with Docker A Programming model
  25. 25. @AnimeshSingh Rules: An association of a trigger and an actionR R := T A Programming model
  26. 26. @AnimeshSingh Actions: Can be chained to create sequences to increase flexibility and foster reuse A AA := A1 + A2 + A3 AB := A2 + A1 + A3 AC := A3 + A1 + A2 Programming model
  27. 27. @AnimeshSingh Packages: A shared collection of triggers and actionsP A A read write T changes A translate A forecast A post T topic Open Source A myAction T myFeed Yours T commit Third Party Programming model
  28. 28. OpenWhisk backend architecture
  29. 29. @AnimeshSingh github.com openwhisk/openwhisk ! ! ! ! core runtime CLIpackages security features persistent store loggingmonitoring billing authenticati on OpenWhisk on Bluemix
  30. 30. @AnimeshSingh Edge! VM! Edge! VM! ! Edge! ! ! ! ! Edge! VM! Edge! VM! Master! ! ! ! ! ! ! ! ! controller Edge! VM! Edge! VM! ! Slave! ! ! ! ! ! ! ! ! ! ! invoker •  microservices deployed in docker containers! •  open-source system middleware! •  NoSQL (CouchDB) persistence! action container! action container! action container! action container! action container! action container! action container! action container OpenWhisk Open Source Core Runtime
  31. 31. Why Docker?
  32. 32. @AnimeshSingh controller invoker Deploying and managing traditional microservices 1 Why Docker?
  33. 33. @AnimeshSingh Slave VM Lightweight isolated execution environment for arbitrary user code action container action container action container action container action container action container action container action container 2 Why Docker?
  34. 34. @AnimeshSingh Portable description of arbitrary binary user actions (Dockerfile) Docker file 3 Why Docker?
  35. 35. @AnimeshSingh % wsk action invoke hello in 8 easy steps How it all works? POST /api/v1/namespaces/myNamespace/actions/myAction
  36. 36. 36 Controller … Invoker InvokerInvoker 1! 2! 3,4! 5! 6! 7! 8! OpenWhisk Topology
  37. 37. @AnimeshSingh Cloudant ELK-Stack Controller Integration Service …InvokerInvokerInvoker Monitoring OpenWhisk Topology in Bluemix
  38. 38. @AnimeshSingh OpenWhisk: Usage of Docker •  Isolation of actions •  Control over consumed resources of each container 38 A = wsk action invoke docker run ≈
  39. 39. @AnimeshSingh OpenWhisk: Container startup 39 Start container docker run Initialize /init Run /run cold container
  40. 40. @AnimeshSingh Start container docker run Initialize /init Run /run OpenWhisk: Container startup 40 pre-warmed container
  41. 41. @AnimeshSingh Start container docker run Initialize /init Run /run OpenWhisk: Container startup 41 warm container
  42. 42. @AnimeshSingh OpenWhisk: Container startup optimization •  Performance is king. 42 cold container pre-warmed container warm container faster
  43. 43. IoT Usecase Node-RED and MQTT
  44. 44. @AnimeshSingh CLIENTS BROKER
  45. 45. @AnimeshSinghSUBSCRIBE PUBLISH {…} {…} {…} {…}
  46. 46. @AnimeshSingh COMMERCIALOPEN-SOURCE MOSQUITTO MOSCA ACTIVEMQ RABBITMQ MESSAGESIGHT HIVEMQ THINGMQ CLOUDMQTT MQTT Brokers
  47. 47. @AnimeshSingh MQTT NODES IN NODE-RED
  48. 48. @AnimeshSingh DEVICES NODE-RED BROKER
  49. 49. @AnimeshSinghDEVICES NODE-RED BROKER
  50. 50. OpenWhisk Feeds and creating MQTT feeds
  51. 51. @AnimeshSingh Trigger Action Action Action push, fork, comment, .. CUSTOM FEED EXAMPLE
  52. 52. @AnimeshSingh anybody can create a Package with a feed /whisk.system/github /mynamespace/github
  53. 53. MQTT feeds for OpenWhisk •  Bridging MQTT messages to OpenWhisk Actions can be achieved by creating a new Feed provider. This provider would subscribe to message topics and execute registered Triggers with incoming messages. •  The custom feed provider would need to establish and maintain long-lived MQTT connections, waiting for messages to arrive. This requirements means the Feed provider needs an external service to handle managing these connections, it won’t be possible within the Feed Action. •  This feed provider service is implemented using Node.js, using Cloudant for the database. The service listens for HTTP requests, with Trigger registration details, from the Feed Action. The Node.js MQTT library is used to subscribe to registered topics. When messages are received, the OpenWhisk client library is used to invoke the Trigger remotely, passing the message contents as event parameters. •  This service provider is packaged using Docker. Pushing this image into the IBM Containers registry, the Feed provider can be started on IBM Bluemix using the Containers service. http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/
  54. 54. MQTT feeds for OpenWhisk •  This service provider is packaged using Docker. •  Pushing this image into the IBM Containers registry, the Feed provider can be started on IBM Bluemix using the Containers service.
  55. 55. Registering Feeds http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/
  56. 56. Node-RED for Serverless OpenWhisk
  57. 57. @AnimeshSingh Node-RED and OpenWhisk •  Community effort to integrate with open tools: NodeRED •  NodeRED is all about automating flows to orchestrate calls to different service APIs •  Usually triggered by calls from external systems or devices •  Runs within a long-running single node process, with a dedicated amount of CPU & memory being allocated •  OpenWhisk is all about executing code (custom logic) in response to events on a scalable platform, with a dedicated amount of CPU & memory being allocated per-request •  NodeRED and OpenWhisk complement each other •  Use NodeRED to graphically create flows, automating a series of tasks in a kind of workflow •  Use OpenWhisk to execute custom logic (requiring some kind of CPU- or memory bound operation) triggered from within NodeRED
  58. 58. @AnimeshSingh •  Use Node-RED to create Multi cloud Serveless Applications! Use Node-RED to compose Serverless Applications $ wsk property set --apihost openwhisk.ng.bluemix.net --auth 96294c7b- e6f4-4ccf --namespace “animeshsingh" $ wsk action invoke /whisk.system/utils/ echo -p message hello --blocking --result { "message": "hello" }
  59. 59. @AnimeshSingh Devices Node-RED & OpenWhisk MQTT Broker Trigger Action Action Action Bringing it all together – Serverless IoT Applications
  60. 60. Summary
  61. 61. @AnimeshSingh What you learned today •  We’re in the early days of an evolution that is empowering developers to write cloud native applications better, faster, and cheaper •  OpenWhisk provides an open source platform to enable cloud native, serverless, event driven applications •  OpenWhisk, MQTT and Node-RED can be used together to create IoT Serverless applications
  62. 62. @AnimeshSingh Experiment with OpenWhisk on Bluemix bit.ly/ow-bm
  63. 63. @AnimeshSingh Join us to build a cloud native platform for the future! OpenWhisk.org dwopen.slack.com #openwhisk bluemix.net OpenWhisk and MQTT http://jamesthom.as/blog/2016/06/15/openwhisk-and-mqtt/
  64. 64. Thank You

×