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
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
How to build a Distributed Serverless Polyglot Microservices IoT Platform using Docker and OpenWhisk
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
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. @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
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. @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. @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
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….
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. @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...
18. What is OpenWhisk?
a high-level serverless programming model
Trigger
Rule
Action
Package
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
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. @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
38. @AnimeshSingh
OpenWhisk: Usage of Docker
• Isolation of actions
• Control over consumed resources of each container
38
A =
wsk action invoke docker run
≈
56. 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/
57. 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.
60. @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
61. @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"
}
64. @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
66. @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/