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.

Serverless APIs with Apache OpenWhisk

289 views

Published on

Materials for the Serverless APIs with Apache OpenWhisk session at OSCON on July 19, 2018

https://conferences.oreilly.com/oscon/oscon-or/public/schedule/detail/67393

Ever been frustrated with a conference schedule app that freezes up when everyone opens it right after the first day’s keynotes? Ever played a mobile game that was so popular that its backend couldn’t keep up with real-time multiplayer interaction? If you’re an app developer, chances are that you’re looking for a better mobile backend architecture that can effectively match user demand at the exact moment it’s needed while taking advantage of new per-request cost models promised by serverless technologies.

The Apache OpenWhisk project (supported by IBM, Adobe, Red Hat, and others) provides a polyglot, autoscaling environment for deploying cloud-native applications driven by data, message, and REST API call events. Daniel Krook explains why serverless architectures are great for cloud workloads and when to consider OpenWhisk in particular for your next web, mobile, IoT, bot, or analytics project.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Serverless APIs with Apache OpenWhisk

  1. 1. © 2017 IBM Corporation l Interconnect 2017 Build serverless web and mobile APIs that scale automatically in response to demand @DanielKrook Daniel Krook Software Engineer & Developer Advocate github.com/krook/oscon
  2. 2. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Increasingfocusonbusinesslogic Decreasing concern (and control) over stack implementation Bare Metal VM VM VM Virtual machines Functions Containers Serverless developers focus more on code, less on infrastructure
  3. 3. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Monolithic Application Break-down into microservices Make each microservice HA Protect against regional outage Region A Region B Microservices can be hard to manage at scale
  4. 4. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Emerging workloads are a good fit for event-driven programming Execute logic in response to database change Perform analytics on sensor input messages Provide cognitive computing via chatbots Schedule tasks performed for a short time Invoke autoscaled APIs and mobile backends
  5. 5. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Memory allocated (MB) Time executing (milliseconds) Instances executing simultaneously (count) Cloud resource cost better matches business value gained Not a silver bullet, but this can result in substantial savings for many workloads New cost models more accurately charge for usage
  6. 6. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Why serverless? Mobile video game popularity is hard to predictNumberofactiveusers (unpredictable) Days since latest release (predictable) Active users curve for a new mobile game has a predictable shape, but an unpredictable volume 1 5 10
  7. 7. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Why serverless? Conference mobile apps have huge variations in demandNumberofactiveusers (massivelyvariable) Days of the week (predictable) Active users curve for a mobile conference app has no demand before and after the conference, and huge intraweek swings in demand Monday Tuesday Wednesday Thursday
  8. 8. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Why serverless? Mobile banking often peaks massively on paydayNumberofactiveusers (stablewithamassivepeak) Days of the pay period (predictable) Mobile banking apps often have peaks in demand on payday, once every two weeks Friday
  9. 9. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Apache OpenWhisk is a cloud platform that executes code in response to events Apache OpenWhisk enables these serverless, event-driven workloads Provides serverless deployment and operations model Runs code only on-demand on a per-request basis Optimized utilization, fine-grained metering at any scale Flexible, extensible, polyglot programming model Open source and open ecosystem (Apache Incubator) Ability to run in public, private, and hybrid models
  10. 10. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Apache Incubator OpenWhisk is built on solid open source foundations
  11. 11. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Apache Incubator The OpenWhisk ecosystem is growing
  12. 12. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon But what about PaaS and container orchestration?Increasingfocusonbusinesslogic Decreasing concern (and control) over stack implementation Full control over infrastructure and maximum portability Focus on the application and let the platform handle the rest Auto-scaled, event-driven applications that respond to a variety of triggers Containers Applications Functions
  13. 13. © 2017 IBM Corporation l Interconnect 2017 Apache OpenWhisk programming model
  14. 14. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Results Developers work with packages, triggers, actions, and rules Package (feed) Packages provide integration with external event sources P Trigger (event) T Data sources define events they emit as Triggers Rule (map)R Action (function) A Developers map Actions to Triggers via Rules Data sources define events they emit as Triggers. Developers map Actions to Triggers via Rules. T A R
  15. 15. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Triggers A class of events that can occurT Social events Data changes Device readings Location updates User input Invocations can be blocking, non-blocking, or periodic
  16. 16. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Actions Code that runs in response to an event (that is, an event handler) A
  17. 17. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Actions Can be written in a variety of languages, such as JavaScript, Python, Java, PHP, and Swift A function main(params) { return { message: 'Hello, ' + params.name + ' from ' + params.place }; }; Multi- language Support JS/NodeJS 8 Java Python 3 Swift 4 Docker PHP 7 Community Efforts Go Rust Ruby … bash C
  18. 18. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Actions Can be written in a variety of languages, such as JavaScript, Python, Java, PHP, and Swift A function main(params) { return { message: 'Hello, ' + params.name + ' from ' + params.place }; };
  19. 19. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Actions Or any other language by packaging with DockerA
  20. 20. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon 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 Plus: • Sequencing • Conditionals • Loops • Error handling
  21. 21. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Rules An association of a trigger to an action in a many to many mapping. R R := T A
  22. 22. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon 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
  23. 23. © 2017 IBM Corporation l Interconnect 2017 Apache OpenWhisk in action
  24. 24. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon OpenWhisk awaits events, fetches mapped code, runs it in a container Pool of actions Swift DockerJS Trigger 1 Running action Running action Running action 3 OpenWhisk Engine 2 A T AAA
  25. 25. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Open source software as a service on the IBM Cloud Open source Hosted service Serverless engine Apache OpenWhisk IBM Cloud Functions API Gateway LoopBack IBM API Gateway Databases Apache CouchDB MySQL IBM Cloudant IBM Compose Message streams Apache Kafka IBM Message Hub
  26. 26. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Demo 1: Your first OpenWhisk trigger, action, and rule $ bx wsk action create handler handler.js $ bx wsk action invoke --blocking handler $ bx wsk trigger create every-20-seconds --feed /whisk.system/alarms/alarm --param cron "*/20 * * * * *" --param maxTriggers 15 $ bx wsk rule create invoke-periodically every-20-seconds handler Trigger 1 Running action 2 T A 1. Cron syntax alarm 2. Log the current time $ bx wsk activation poll
  27. 27. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Demo 2: Mapping an HTTP request to an action These demo actions are written in JavaScript. But you could write the equivalent in Swift to reuse the same skills on mobile device and backend services.
  28. 28. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Demo 3: HTTP REST APIs with full create, read, update, delete methods
  29. 29. Serverless Web and Mobile APIs@DanielKrook github.com/krook/oscon Delivered as
 Open source via Apache openwhisk.org Managed OpenWhisk with IBM Cloud Functions bluemix.net/openwhisk Get started with Apache OpenWhisk github.com/openwhisk slack.openwhisk.org twitter.com/openwhisk medium.com/openwhisk
  30. 30. © 2017 IBM Corporation l Interconnect 2017 Build serverless web and mobile APIs that scale automatically in response to demand @DanielKrook Daniel Krook Software Engineer & Developer Advocate github.com/krook/oscon

×