Serverless apps
with OpenWhisk
Cloud native • Event driven • Microservices
Andrew Bodine • Software Engineer • IBM Cloud • @bodine_andrew
OpenWhisk.org
@DanielKrookOpenWhisk.org
What you will learn today
• How cloud has evolved to enable developers to write cloud native
applications better, faster, and cheaper using serverless technology.
• How OpenWhisk provides an open source platform to enable cloud
native, serverless, event driven applications.
• How to get started developing with OpenWhisk on Bluemix, or find out
more about the underlying open source serverless platform.
OpenWhisk.org @DanielKrook
What makes serverless,
event driven computing
so compelling?
@DanielKrookOpenWhisk.org
Cloud evolution means developers can write apps better, faster, and cheaper
Bare
metal
Virtual
machines
Containers
Functions
Decreasing concern (and control) over stack implementation
Increasingfocusonbusinesslogic
@DanielKrookOpenWhisk.org
Newer workloads are a better fit for event driven programming
Execute app logic in response to database triggers
Execute app logic in response to sensor data
Execute app logic in response to cognitive trends
Execute app logic in response to scheduled tasks
Provide easy server-side backend for mobile app
@DanielKrookOpenWhisk.org
Problem: It’s expensive to scale microservices
Explosion in number of container
/ processes:
1. Increase of infrastructure cos
footprint
2. Increase of operational
management cost and
complexity
Region BRegion A
Break-down into microservices
Make each micro service HA
Protect against regional outages
Monolithic application
@DanielKrookOpenWhisk.org
Serverless can handle many cloud native app 12 Factors
I Codebase Handled by developer (Manage versioning of functions on their own)
II Dependencies Handled by developer, facilitated by serverless platform (Runtimes and packages)
III Config Handled by platform (Environment variables or injected event parameters)
IV Backing services Handled by platform (Connection information injected as event parameters)
V Build, release, run Handled by platform (Deployed resources are immutable and internally versioned)
VI Processes Handled by platform (Single stateless containers often used)
VII Port binding Handled by platform (Actions or functions are automatically discovered)
VIII Concurrency Handled by platform (Process model is hidden and scales in response to demand)
IX Disposability Handled by platform (Lifecycle is hidden from the user, fast startup and elastic scale is prioritized)
X Dev/prod parity Handled by developer (The developer is the deployer. Scope of what differs is narrower)
XI Logs Handled by platform (Developer writes to console.log, platform handles log streaming)
XII Admin processes Handled by developer (No distinction between one off processes and long running)
@DanielKrookOpenWhisk.org
Problem: Programming and pricing models aren’t ideal
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 VMCF
2
Polling
1b
Request
1a
@DanielKrookOpenWhisk.org
Cost model offers a better match between app and resources
Applications charged by compute time
(millisecond) rather than reserved
memory (GB/hour).
While many applications must still be deployed in a daemon
model, serverless provides an alternative that can mean
substantial cost savings for a variety of event driven workloads.
Greater linkage between cloud
resources used and business
operations executed.
@DanielKrookOpenWhisk.org
Technological and business factors make serverless compelling
Serverless platforms and frameworks are gaining traction
Cost models getting more granular and efficient
Growth of event driven workloads that need automated scale
Platforms evolving to facilitate cloud native design for developers
OpenWhisk.org @DanielKrook
Introducing
OpenWhisk
@DanielKrookOpenWhisk.org
OpenWhisk in a nutshell
OpenWhisk is a cloud platform
that executes code
in response to events
OpenWhisk
@DanielKrookOpenWhisk.org
OpenWhisk is different than other hosted services
Serverless deployment and operations model
Optimized utilization, fine grained metering at any scale
Flexible programming model with powerful tooling
Open source and open ecosystem (moving to Apache)
Ability to run in public, private, and hybrid models
OpenWhisk
@DanielKrookOpenWhisk.org
OpenWhisk supports many growing workloads
OpenWhisk can help power
various mobile, web and IoT app
use cases by simplifying the
programming model of
orchestrating various services
using events without a dedicated
backend.
Digital app workloads Big Data/Analytics pipeline
Complex data pipelines for Big
Data/Analytics tasks can be scripted
using changes in data services or
streams for near real-time analytics
and feedback.
DevOps and infrastructure as code
OpenWhisk can be used to
automate DevOps pipelines
based on events triggered from
successful builds, or completed
staging, or a go-live event.
Microservices builder
OpenWhisk can be used to easily
build microservices given the
footprint and programming model
desired by microservices
OpenWhisk.org @DanielKrook
The OpenWhisk
programming model
@DanielKrookOpenWhisk.org
Triggers, actions, rules (and packages)
Data sources define the events they emit as triggers.
Developers associate actions to handle the events via rules.
T A R
@DanielKrookOpenWhisk.org
Triggers
A class of events that can occurT
Social events
Data changes
Device readings Location updates
User input
@DanielKrookOpenWhisk.org
Actions
Code that runs in response to an event
(that is, an event handler)
A
@DanielKrookOpenWhisk.org
Actions
Can be written in a variety of languages, such as
JavaScript, Python, Java, and Swift
A
function main(params) {
return { message: 'Hello, ' + params.name + ' from ' + params.place };
};
@DanielKrookOpenWhisk.org
Actions
Or any other language by packaging with DockerA
@DanielKrookOpenWhisk.org
Actions
Can be composed to create sequences
that increase flexibility and foster reuse
A
AA
:= A1
+ A2
+ A3
AB := A2
+ A1
+ A3
AC
:= A3
+ A1
+ A2
@DanielKrookOpenWhisk.org
Rules
An association of a trigger to an action
in a many to many mapping.
R
R := T A
@DanielKrookOpenWhisk.org
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
OpenWhisk.org @DanielKrook
OpenWhisk
in action
@DanielKrookOpenWhisk.org
The OpenWhisk execution model
Pool of actions
Swift DockerJS
Trigger
1
Running
action
Running
action
Running
action
3
OpenWhisk
Engine
2 A
T
AAA
OpenWhisk.org @DanielKrook
Demo 1: Create a
timer triggered action
@DanielKrookOpenWhisk.org
Demo 1: Timer triggered action
Trigger
1
Running
action
2
T
A
Cron syntax alarm
Log the current time
$ wsk action create handler handler.js
$ wsk action invoke --blocking handler
$ wsk trigger create every-20-seconds 
--feed /whisk.system/alarms/alarm
--param cron “*/20 * * * * *”
$ wsk rule create 
invoke-periodically 
every-20-seconds 
handler
$ wsk activation poll
bit.ly/ow-demo-1
@DanielKrookOpenWhisk.org
OpenWhisk enables event driven applications
Event
Providers
Cloudant
GitHub
Weather
…
Which triggers execution of
associated OpenWhisk action
2
Slack
JS Swift Docker …
An event occurs, for example
• Commit pushed to GitHub repository
• Data changed in Cloudant
1
OpenWhisk
@DanielKrookOpenWhisk.org
OpenWhisk can implement REST microservices
Send HTTP request
HTTP GET
app.com/customers
1
Invoke OpenWhisk
action get-customers
Browser
Mobile App
Web App
2
JS Swift Docker …
OpenWhisk
API
Proxy
OpenWhisk.org @DanielKrook
Demo 2: Create
a Slack bot
@DanielKrookOpenWhisk.org
Demo 2: Create a Slack bot
bit.ly/ow-demo-2
GET /register
POST /command
POST /event
Register
action
Event
action
Command
action
2
OpenWhisk
Engine
1
AAA
API
Proxy
Register
the bot
Respond
to direct
messages
Respond
to slash
commands
OpenWhisk.org @DanielKrook
OpenWhisk
high level
implementation
architecture
@DanielKrookOpenWhisk.org
OpenWhisk design principles
1. Provide an open interface for event providers
2. Offer polyglot support and simple extensibility for new runtimes
3. Support higher level constructs as appropriate (e.g. action sequences)
4. Scale dynamically on a per request basis
5. Enable sharing of actions and event providers
6. Leverage best of breed open source software (Docker, Kafka, Consul, …)
7. Use the Apache 2 License
OpenWhisk.org @DanielKrook
OpenWhisk under the hood: A deeper look
bit.ly/ow-int
1. Entering the system: nginx
2. Really entering the system: Controller
3. Authentication and Authorization: CouchDB
4. Getting the action: CouchDB… again
5. Who’s there to invoke the action: Consul
6. Please form a line: Kafka
7. Actually invoking the code already: Invoker
8. Storing the results: Yes… CouchDB again
OpenWhisk.org @DanielKrook
Summary
@DanielKrookOpenWhisk.org
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
• Bluemix provides a hosted instance of OpenWhisk that you can use to
get started (and offers integration with a catalog of services)
@DanielKrookOpenWhisk.org
Experiment with OpenWhisk on Bluemix
bit.ly/ow-bm
OpenWhisk.org @DanielKrook
Backup
@DanielKrookOpenWhisk.org
Join us to build a cloud native platform for the future!
OpenWhisk.org
dwopen.slack.com #openwhisk
bluemix.net
@DanielKrookOpenWhisk.org
Watson IOT OpenWhisk
Customer
registry
Shipping system SendGrid
Service
reports
actions
IBM Cloud
LOB, SoR
systems &
databases
Need a
new filter
Email: Filter
on its way!
bit.ly/open-fridge
@DanielKrookOpenWhisk.org
analyze
reading
OpenWhisk
create
order
alert
customer
alarm
changes changes
service order appliance
feed
Watson
IoT
A A AT
T T
T
P
P
P
bit.ly/open-fridge

OpenWhisk - Serverless Architecture

  • 1.
    Serverless apps with OpenWhisk Cloudnative • Event driven • Microservices Andrew Bodine • Software Engineer • IBM Cloud • @bodine_andrew OpenWhisk.org
  • 2.
    @DanielKrookOpenWhisk.org What you willlearn today • How cloud has evolved to enable developers to write cloud native applications better, faster, and cheaper using serverless technology. • How OpenWhisk provides an open source platform to enable cloud native, serverless, event driven applications. • How to get started developing with OpenWhisk on Bluemix, or find out more about the underlying open source serverless platform.
  • 3.
    OpenWhisk.org @DanielKrook What makesserverless, event driven computing so compelling?
  • 4.
    @DanielKrookOpenWhisk.org Cloud evolution meansdevelopers can write apps better, faster, and cheaper Bare metal Virtual machines Containers Functions Decreasing concern (and control) over stack implementation Increasingfocusonbusinesslogic
  • 5.
    @DanielKrookOpenWhisk.org Newer workloads area better fit for event driven programming Execute app logic in response to database triggers Execute app logic in response to sensor data Execute app logic in response to cognitive trends Execute app logic in response to scheduled tasks Provide easy server-side backend for mobile app
  • 6.
    @DanielKrookOpenWhisk.org Problem: It’s expensiveto scale microservices Explosion in number of container / processes: 1. Increase of infrastructure cos footprint 2. Increase of operational management cost and complexity Region BRegion A Break-down into microservices Make each micro service HA Protect against regional outages Monolithic application
  • 7.
    @DanielKrookOpenWhisk.org Serverless can handlemany cloud native app 12 Factors I Codebase Handled by developer (Manage versioning of functions on their own) II Dependencies Handled by developer, facilitated by serverless platform (Runtimes and packages) III Config Handled by platform (Environment variables or injected event parameters) IV Backing services Handled by platform (Connection information injected as event parameters) V Build, release, run Handled by platform (Deployed resources are immutable and internally versioned) VI Processes Handled by platform (Single stateless containers often used) VII Port binding Handled by platform (Actions or functions are automatically discovered) VIII Concurrency Handled by platform (Process model is hidden and scales in response to demand) IX Disposability Handled by platform (Lifecycle is hidden from the user, fast startup and elastic scale is prioritized) X Dev/prod parity Handled by developer (The developer is the deployer. Scope of what differs is narrower) XI Logs Handled by platform (Developer writes to console.log, platform handles log streaming) XII Admin processes Handled by developer (No distinction between one off processes and long running)
  • 8.
    @DanielKrookOpenWhisk.org Problem: Programming andpricing models aren’t ideal 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 VMCF 2 Polling 1b Request 1a
  • 9.
    @DanielKrookOpenWhisk.org Cost model offersa better match between app and resources Applications charged by compute time (millisecond) rather than reserved memory (GB/hour). While many applications must still be deployed in a daemon model, serverless provides an alternative that can mean substantial cost savings for a variety of event driven workloads. Greater linkage between cloud resources used and business operations executed.
  • 10.
    @DanielKrookOpenWhisk.org Technological and businessfactors make serverless compelling Serverless platforms and frameworks are gaining traction Cost models getting more granular and efficient Growth of event driven workloads that need automated scale Platforms evolving to facilitate cloud native design for developers
  • 11.
  • 12.
    @DanielKrookOpenWhisk.org OpenWhisk in anutshell OpenWhisk is a cloud platform that executes code in response to events OpenWhisk
  • 13.
    @DanielKrookOpenWhisk.org OpenWhisk is differentthan other hosted services Serverless deployment and operations model Optimized utilization, fine grained metering at any scale Flexible programming model with powerful tooling Open source and open ecosystem (moving to Apache) Ability to run in public, private, and hybrid models OpenWhisk
  • 14.
    @DanielKrookOpenWhisk.org OpenWhisk supports manygrowing workloads OpenWhisk can help power various mobile, web and IoT app use cases by simplifying the programming model of orchestrating various services using events without a dedicated backend. Digital app workloads Big Data/Analytics pipeline Complex data pipelines for Big Data/Analytics tasks can be scripted using changes in data services or streams for near real-time analytics and feedback. DevOps and infrastructure as code OpenWhisk can be used to automate DevOps pipelines based on events triggered from successful builds, or completed staging, or a go-live event. Microservices builder OpenWhisk can be used to easily build microservices given the footprint and programming model desired by microservices
  • 15.
  • 16.
    @DanielKrookOpenWhisk.org Triggers, actions, rules(and packages) Data sources define the events they emit as triggers. Developers associate actions to handle the events via rules. T A R
  • 17.
    @DanielKrookOpenWhisk.org Triggers A class ofevents that can occurT Social events Data changes Device readings Location updates User input
  • 18.
    @DanielKrookOpenWhisk.org Actions Code that runsin response to an event (that is, an event handler) A
  • 19.
    @DanielKrookOpenWhisk.org Actions Can be writtenin a variety of languages, such as JavaScript, Python, Java, and Swift A function main(params) { return { message: 'Hello, ' + params.name + ' from ' + params.place }; };
  • 20.
    @DanielKrookOpenWhisk.org Actions Or any otherlanguage by packaging with DockerA
  • 21.
    @DanielKrookOpenWhisk.org Actions Can be composedto create sequences that increase flexibility and foster reuse A AA := A1 + A2 + A3 AB := A2 + A1 + A3 AC := A3 + A1 + A2
  • 22.
    @DanielKrookOpenWhisk.org Rules An association ofa trigger to an action in a many to many mapping. R R := T A
  • 23.
    @DanielKrookOpenWhisk.org Packages A shared collectionof 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
  • 24.
  • 25.
    @DanielKrookOpenWhisk.org The OpenWhisk executionmodel Pool of actions Swift DockerJS Trigger 1 Running action Running action Running action 3 OpenWhisk Engine 2 A T AAA
  • 26.
    OpenWhisk.org @DanielKrook Demo 1:Create a timer triggered action
  • 27.
    @DanielKrookOpenWhisk.org Demo 1: Timertriggered action Trigger 1 Running action 2 T A Cron syntax alarm Log the current time $ wsk action create handler handler.js $ wsk action invoke --blocking handler $ wsk trigger create every-20-seconds --feed /whisk.system/alarms/alarm --param cron “*/20 * * * * *” $ wsk rule create invoke-periodically every-20-seconds handler $ wsk activation poll bit.ly/ow-demo-1
  • 28.
    @DanielKrookOpenWhisk.org OpenWhisk enables eventdriven applications Event Providers Cloudant GitHub Weather … Which triggers execution of associated OpenWhisk action 2 Slack JS Swift Docker … An event occurs, for example • Commit pushed to GitHub repository • Data changed in Cloudant 1 OpenWhisk
  • 29.
    @DanielKrookOpenWhisk.org OpenWhisk can implementREST microservices Send HTTP request HTTP GET app.com/customers 1 Invoke OpenWhisk action get-customers Browser Mobile App Web App 2 JS Swift Docker … OpenWhisk API Proxy
  • 30.
  • 31.
    @DanielKrookOpenWhisk.org Demo 2: Createa Slack bot bit.ly/ow-demo-2 GET /register POST /command POST /event Register action Event action Command action 2 OpenWhisk Engine 1 AAA API Proxy Register the bot Respond to direct messages Respond to slash commands
  • 32.
  • 33.
    @DanielKrookOpenWhisk.org OpenWhisk design principles 1.Provide an open interface for event providers 2. Offer polyglot support and simple extensibility for new runtimes 3. Support higher level constructs as appropriate (e.g. action sequences) 4. Scale dynamically on a per request basis 5. Enable sharing of actions and event providers 6. Leverage best of breed open source software (Docker, Kafka, Consul, …) 7. Use the Apache 2 License
  • 34.
    OpenWhisk.org @DanielKrook OpenWhisk underthe hood: A deeper look bit.ly/ow-int 1. Entering the system: nginx 2. Really entering the system: Controller 3. Authentication and Authorization: CouchDB 4. Getting the action: CouchDB… again 5. Who’s there to invoke the action: Consul 6. Please form a line: Kafka 7. Actually invoking the code already: Invoker 8. Storing the results: Yes… CouchDB again
  • 35.
  • 36.
    @DanielKrookOpenWhisk.org What you learnedtoday • 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 • Bluemix provides a hosted instance of OpenWhisk that you can use to get started (and offers integration with a catalog of services)
  • 37.
  • 38.
  • 39.
    @DanielKrookOpenWhisk.org Join us tobuild a cloud native platform for the future! OpenWhisk.org dwopen.slack.com #openwhisk bluemix.net
  • 40.
    @DanielKrookOpenWhisk.org Watson IOT OpenWhisk Customer registry Shippingsystem SendGrid Service reports actions IBM Cloud LOB, SoR systems & databases Need a new filter Email: Filter on its way! bit.ly/open-fridge
  • 41.