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: The Missing Manual

158 views

Published on

Believing the analysts Serverless Computing will be the “next big thing”. Thanks to NoOps, writing a serverless function and bringing it to production is quite easy. And also combining some of them to build up a more complex system seems to be not too complicated at all. But what are suitable scenarios for Serverless Computing? When to favor serverless over other architectural approaches and when not? Are there any specific patterns to be aware of when applying serverless? How does the serverless paradigm influence the software lifecycle, e.g. testing and monitoring? A lot of open questions to be answered!

Published in: Software
  • Be the first to comment

  • Be the first to like this

Serverless: The Missing Manual

  1. 1. #WISSENTEILEN Serverless Lars Röwekamp | open knowledge GmbH @_openKnowledge | @mobileLarson The Missing Manual
  2. 2. ÜBER OPEN KNOWLEDGE Branchenneutrale Softwareentwicklung & IT-Beratung
  3. 3. ÜBER MICH Wer bin ich - und wenn ja, wie viele? • CIO New Technologies • Enterprise & Mobile • Autor, Speaker, Coach & Mentor • Snowboard & MTB Enthusiast (a.k.a. “stets bemüht“) Lars Röwekamp (a.k.a. @mobileLarson)
  4. 4. Was ist die Idee von Serverless?
  5. 5. #WISSENTEILEN Run code, not servers Serverless Function: Entwickler schreibt eine Business- Funktion, „bundled“ diese mit den entsprechenden Abhängigkeiten (LIBs) und lädt sie in die Cloud. Serverless Environment: Führt die Funktion bei „Aufruf“ in der passenden Runtime effizient, flexibel und hoch skalierbar aus. “
  6. 6. #WISSENTEILEN No machines, VMs or containers* Entwickler: Fokussiert sich ausschließlich auf die Umsetzung der Business-Logik und das Erstellen des Function-Bundle. Cloud Provider: liefert und maintained rundum-sorglos Umgebung für die Serverless Functions, inklusive etwaiger Cloud Services (z.B. Storage, DB, Streaming, AI). “
  7. 7. > Hands-On
  8. 8. AWS Cloud 1 trigger request Hands-on: Hello World
  9. 9. AWS Cloud hello world serverless context 1 trigger request Hands-on: Hello World
  10. 10. AWS Cloud hello world serverless context HelloWorld Logs 1 trigger request 2 Hands-on: Hello World
  11. 11. #WISSENTEILEN “Run your business code highly-available in the cloud in response to events and scale without any servers to manage.“* * AWS Lambda Advertising
  12. 12. #1: Run your business code
  13. 13. #2: No servers to provision or manage
  14. 14. #3: Build in high availability and disaster recovery
  15. 15. #4: Scale with usage by design
  16. 16. Management: “Hmm, ich bin noch nicht überzeugt!.”
  17. 17. #5: Never pay idle (Management: „Ok, I bin definitv dabei!“)
  18. 18. Big Players?
  19. 19. AWS Lambda Microsoft Azure Functions Oracle Functions a.k.a. Project FN*** IBM Cloud Functions a.k.a Apache OpenWhisk** Google Cloud Functions Project Riff sponsored by Pivotal
  20. 20. Serverless Szenarien
  21. 21. Szenario #1
  22. 22. Szenario #1: Datei-/Datenbearbeitung Datei- oder Datenbearbeitung nach Ablage im Storage System • Bildbearbeitung • Thumbnail-Erzeugung • PDF-Generierung
  23. 23. AWS Cloud Szenario #1: Datei-/Datenbearbeitung 1 upload image
  24. 24. AWS Cloud Szenario #1: Datei-/Datenbearbeitung 1 2 upload image
  25. 25. AWS Cloud Store raw Image Szenario #1: Datei-/Datenbearbeitung StoreImage Logs 1 2 3 upload image
  26. 26. AWS Cloud Store raw Image Szenario #1: Datei-/Datenbearbeitung StoreImage Logs S3 Object created1 2 3 4 upload image
  27. 27. AWS Cloud Store raw Image Szenario #1: Datei-/Datenbearbeitung StoreImage Logs S3 Object created1 2 3 4 upload image
  28. 28. AWS Cloud Create ThumbnailStore raw Image Szenario #1: Datei-/Datenbearbeitung StoreImage Logs CreateThumbnail Logs S3 Object created1 2 3 4 5 upload image
  29. 29. Szenario #2
  30. 30. Szenario #3: Stream Processing Regelmäßiges Abarbeiten von Streaming Data • Social Media Trendanalysen • Sensor Data Monitoring / Anomaly Detection
  31. 31. AWS Cloud 1 sensor data stream is uploaded to Kinesis in real-time Szenario #3: Stream Processing tons of very important sensor data
  32. 32. AWS Cloud 1 sensor data stream is uploaded to Kinesis in real-time Szenario #3: Stream Processing tons of very important sensor data
  33. 33. AWS Cloud Data Stream Analysis StreamAnalyzer Logs 1 sensor data stream is uploaded to Kinesis in real-time 2 Lambda runs code to detect anomalies Szenario #3: Stream Processing tons of very important sensor data
  34. 34. AWS Cloud Data Stream Analysis StreamAnalyzer Logs store anomalies extracted by lambda function 1 sensor data stream is uploaded to Kinesis in real-time 2 3 Lambda runs code to detect anomalies Szenario #3: Stream Processing tons of very important sensor data
  35. 35. AWS Cloud Data Stream Analysis StreamAnalyzer Logs Real-Time Monitoring / Querying store anomalies extracted by lambda function 1 sensor data stream is uploaded to Kinesis in real-time 2 3 Lambda runs code to detect anomalies 4 data immediately available for interested parties to query Szenario #3: Stream Processing tons of very important sensor data
  36. 36. Szenario #3
  37. 37. Szenario #4: Web Application Serverless „all in“ einer Anwendung… • Ausliefern von statischem Content via CDN • Authentication / Autorization via BaaS • Businesslogik via FaaS (unter Verwendung von PaaS)
  38. 38. Szenario #4: Web Application AWS Cloud Web Client region aware web app delivery 1
  39. 39. Szenario #4: Web Application AWS Cloud Web Client region aware web app delivery 1 login via id/pwd returns JWT 2
  40. 40. Szenario #4: Web Application AWS Cloud Web Client region aware web app delivery 1 login via id/pwd returns JWT 2 3 REST call
  41. 41. Szenario #4: Web Application AWS Cloud Web Client region aware web app delivery 1 login via id/pwd returns JWT 2 3 REST call 4 translated lambda trigger
  42. 42. Szenario #4: Web Application AWS Cloud Web Client storage related functions region aware web app delivery 1 login via id/pwd returns JWT 2 3 REST call 4 translated lambda trigger 5 lambda @work
  43. 43. Szenario #4: Web Application AWS Cloud Web Client storage related functions database related functions region aware web app delivery 1 login via id/pwd returns JWT 2 3 REST call 4 translated lambda trigger 5 lambda @work 5 lambda @work
  44. 44. Szenario #4: Web Application AWS Cloud Web Client storage related functions database related functions additional functions, e.g. region aware web app delivery 1 login via id/pwd returns JWT 2 6 3 REST call 4 translated lambda trigger 5 lambda @work 5 lambda @work
  45. 45. The Road to the Cloud ... Der Serverless Showcase
  46. 46. Web Image Gallery (easy version) GET ../images/{imageId} PUT ../images/{imageId} DELETE ../images/{imageId} POST ../images/
  47. 47. Web Image Gallery (not so easy version) GET ../images/{imageId} PUT ../images/{imageId} DELETE ../images/{imageId} POST ../images/
  48. 48. Web Image Gallery (real life version) GET ../images/{imageId} PUT ../images/{imageId} DELETE ../images/{imageId} POST ../images/
  49. 49. Reality Check
  50. 50. The Road to the Cloud ... Der Serverless Showcase
  51. 51. AWS Cloud Use-Case: Upload Image upload image with additional information
  52. 52. AWS Cloud Store raw Image 1 Use-Case: Upload Image upload image with additional information
  53. 53. AWS Cloud Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  54. 54. AWS Cloud AWS Step Functions workflow: Store Image Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  55. 55. AWS Cloud AWS Step Functions workflow: Store Image Create ThumbnailStore raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  56. 56. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  57. 57. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  58. 58. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  59. 59. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  60. 60. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2 Use-Case: Upload Image upload image with additional information
  61. 61. „Was kann da schon schiefgehen?“
  62. 62. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  63. 63. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  64. 64. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  65. 65. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  66. 66. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  67. 67. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  68. 68. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  69. 69. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  70. 70. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  71. 71. AWS Cloud AWS Step Functions workflow: Store Image Create Thumbnail Inform Subscribers Store raw Image Store Image Information 1 2
  72. 72. „Run Code, not Servers!“
  73. 73. “Run your business code highly-available in the cloud in response to events and scale without any servers to manage.“* *(AWS Lambda product description)
  74. 74. “Run your business code highly distributed and event driven in a non transparent environment with no single point of control.“* *(my personal interpretation)
  75. 75. Wie teste ich? meine Serverless Application
  76. 76. Was, wann, wie und wo sollte ich testen, um … • Vertrauen in meinen Code zu gewinnen • das Risiko von Fehlern zu minimieren* * vor allem in Produktion
  77. 77. Testen in der traditionellen Welt
  78. 78. Testen in der Serverless Welt „The biggest complexity is not within the function itself, but in how it interacts with other functions and services (a.k.a. cloud components).“
  79. 79. Testen in der Serverless Welt Ziele des Testens: „Risiko minimieren“ • Risiko Konfiguration • Risiko technischer Workflow • Risiko Businesslogik • Risiko Integration
  80. 80. Testen in der Serverless Welt Ziele des Testens: „Risiko minimieren“ • Risiko Konfiguration • Risiko technischer Workflow • Risiko Businesslogik • Risiko Integration
  81. 81. Testen in der Serverless Welt
  82. 82. „Don‘t let your users test your code!“
  83. 83. „Welche Art von ‚Benchmarks‘ wollen wir für unser Testing?“ • funktionale Änderungen schnell/kosteneffizient testen • integrative Änderungen schnell/kosteneffizient testen • integrative Änderungen so „real“ wie möglich testen • Use-Cases und User-Stories so „real“ wie möglich testen Testing Best Practices
  84. 84. #1 Trennen von Businesslogik und Infrastruktur Testing Best Practices AWS CloudOn-Premise handler logic Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests u
  85. 85. Infrastructure Business Logic
  86. 86. Infrastructure Business Logic
  87. 87. Business Logic Tests
  88. 88. #2 Cloud-Infrastruktur Komponenten mocken Testing Best Practices AWS CloudOn-Premise handler logic u um Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  89. 89. Infrastructure
  90. 90. AWS agnostic logger (log4j2)
  91. 91. fake infrastructure component (Context)
  92. 92. mock infrastructure component (Context)
  93. 93. #3 Lokale Umgebung für funktionale Tests verwenden (z.B. SAM local) Testing Best Practices AWS CloudOn-Premise handler logic uvia SAM local via SAM local SAM yaml TEST u u Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  94. 94. $ sam local invoke "Greetings" -e event-greeting.json --env-vars env.json function name payload for function
  95. 95. $ sam local invoke "Greetings" -e event-greeting.json --env-vars env.json function name payload for function
  96. 96. #4 Lokale Umgebung zum Triggern von Integration Tests verwenden Testing Best Practices AWS CloudOn-Premise handler logic uvia SAM local via SAM local SAM yaml TEST u u i i Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  97. 97. $ sam local start-api –p 8080
  98. 98. $ sam local start-api –p 8080
  99. 99. $ sam local start-api –p 8080
  100. 100. #5 Lokale Cloud-Komponenten für Integration Tests* Testing Best Practices AWS CloudOn-Premise handler logic u via DynamoDB local via FakeS3 via SAM local via SAM local SAM yaml TEST u u i i i i WARNUNG: lokale Cloud Komponenten können lediglich funktionale Korrektheit sicherstellen, nicht aber infrastrukturelle, wie z.B. DLQs, Timeouts, Throttling, SLAs, … Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  101. 101. $ sam local generate-event [SERVICE] [OPTION] Simulate Component Event to trigger Lambda
  102. 102. $ sam local generate-event [SERVICE] [OPTION] Simulate Component Event to trigger Lambda
  103. 103. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables $ java –jar DynamoDBLocal.-jar
  104. 104. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables
  105. 105. Simulate Component triggered by Lambda $ aws –endpoint-url=http://localhost:8000 dynamodb list-tables
  106. 106. #6 temporäre Integration-Cloud für partielle Integration Tests Testing Best Practices AWS CloudOn-Premise handler logic uvia SAM local via SAM local SAM yaml TEST u u via DynamoDB local via FakeS3 i i Temorary Intregration #Dev1 ii INT i i Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  107. 107. #7 permanente Integration-Cloud für End-to-End Tests Testing Best Practices AWS CloudOn-Premise handler logic uvia SAM local via SAM local SAM yaml TEST u u via DynamoDB local via FakeS3 i i Permament IntregrationINT e e e e i i Kandidat für Unit Tests e i u Kandidat für Integration Tests Kandidat für End-to-Ende Tests
  108. 108. „Sind wir endlich fertig?“
  109. 109. Testing endet nicht in Produktion!
  110. 110. Testing in Produktion Ziele des Testens: „Vertrauen gewinnen“ • Outages von Cloud & Cloud-Komponenten • Outages von 3rd Party Apps • Bugs / Probleme durch Skalierung
  111. 111. Testing in Produktion Robustes Monitoring und Error Reporting • Logging • Tracing • Metrics • Alerting Vorhersagen von Störungen inklusive automatischer Regenerierung!
  112. 112. Testing in Produktion Chaos Engineering • bewusst kleine “Probleme“ und „Fehler“ in das System einstreuen!
  113. 113. Wie monitore ich? meine Serverless Application
  114. 114. Mit einem gut geplantes Monitoring sollten wir in der Lage sein, … • aufkommende Probleme vorherzusagen • schnell die Ursache von Problemen zu identifizieren • automatische Recovery-Prozesse anzustoßen • notwendige Alarme zu triggern Real-Life Monitoring
  115. 115. Real-Life Monitoring Business KPI UX SLA “Produkte pro Bestellung” “Durchschnittlicher Bestellwert” “Abbruchrate” “Erste Darstellung von Inhalten” “Erste sinnvolle Darstellung" “Erste Interaktion” “Verfügbarkeit” “Latenz” “Beständigkeit” “Konsistenz”
  116. 116. Gut geplantes Monitoring berücksichtigt verschiedene Aspekte • reliability: Komponenten und Kommunikation • usage: funktional und nicht-funktional • performance: Dauer, Latenz und Timeouts • security: Zugriffsrechte, Attacken • costs: aktuelle Kosten, Kostenentwicklung Real-Life Monitoring
  117. 117. Die 4 Säulen des Monitorings 3 2 4 1 Tracing Metrics Alerting Logging
  118. 118. 3 2 Tracing Metrics 4 4 Alerting Die 4 Säulen des Monitorings Repräsentiert den State einer Anwendung. Wenn etwas schiefläuft benötigen wir LOGs, um herauszufinden, welche Änderungen am State den Fehler verursacht haben. 1 Logging Logging
  119. 119. 3 Metrics 4 1 Alerting Logging Die 4 Säulen des Monitorings Tracing 2 Repräsentiert eine einzelne „User‘s Journey“ durch den gesamten Stack der Anwendung. Tracing wird oft zur Optimierung des Systems genutzt. Tracing
  120. 120. 2 Tracing 4 1 Alerting Logging Die 4 Säulen des Monitorings 3 Metrics Repräsentiert einen über einen Zeitraum aggregierten Messpunkt. Hilft dabei, den aktuellen „Health-Status“ des Systems sowie dessen Entwicklung festzustellen. Metrics
  121. 121. 3 2 Tracing Metrics 1 Logging Die 4 Säulen des Monitorings 4 Alerting Die Komponente des Monitorings, die basierende auf Metriken, Aktionen auslöst. Meist zur automatischen „Selbstheilung“ verwendet oder im zuständige Personen zu informieren. Alerting
  122. 122. Für ein gut geplantes Monitoring, sollten man daher … • Events loggen, die eine State Transformation anstoßen • Standard-Metriken sammeln • Custom-Metriken definieren und sammeln • Distributed Tracing ermöglichen • Alarme auf individuellem und aggregierten Level definieren Serverless Application Monitoring
  123. 123. Monitoring Strategie AWS Cloud Logging Tracing Metrics Alerting
  124. 124. Monitoring Strategie: Plattform Services AWS Cloud Logging Logging Tracing Metrics Alerting
  125. 125. Monitoring Strategie: Plattform Services AWS Cloud Logging Alerting Metrics “BASIC ALERTING FOR FREE” “BASIC METRICS FOR FREE” Logging Tracing Metrics Alerting
  126. 126. Monitoring Strategie: Plattform Services AWS Cloud Alarm Logging Alerting Metrics Logging Tracing Metrics Alerting
  127. 127. Monitoring Strategie: Plattform Services AWS Cloud Logging Alerting Metrics Tracing (still DIY) Alarm Metrics Logging Tracing Metrics Alerting
  128. 128. Monitoring Strategie: Plattform Services AWS Cloud Alarm Logging Tracing Alerting Tracing (DIY) Metrics Logging Tracing Metrics Alerting
  129. 129. Monitoring Strategie #2: Plattform Services Logging Tracing Metrics Alerting
  130. 130. Monitoring Strategie #2: Plattform Services Logging Tracing Metrics Alerting
  131. 131. Monitoring Strategie #2: Plattform Services Logging Tracing Metrics Alerting
  132. 132. „Welche Art von ‚Benchmarks‘ wollen wir für unser Monitoring?“ • Sammeln von umfangreichen System- und Anwendungsmetriken • Metriken und Logs sollten keine User-facing Latency verursachen • Metriken und Logs sollten in Real-Time verfügbar sein • Metriken und Logs sollten granular und korreliert vorliegen Monitoring Best Practices
  133. 133. #1 User-facing Latency vermeiden Monitoring Best Practices AWS Cloud My Lambda logs log stream log data async sync Log Aggregator log data 1 very fast and cheap 2 3 time consuming and “expensive” parse log stream
  134. 134. #2 umfangreiche System-/Anwendungsmetriken sammeln Monitoring Best Practices AWS Cloud My Lambda logs log stream log data async sync Log Aggregator metrics custom metrics custom metrics log data 2 3 1 very fast and cheap parse log stream custom metrics
  135. 135. #3 unnötige Kosten vermeiden Monitoring Best Practices AWS Cloud My Lambda logs log stream log data async sync Log Aggregator metrics custom metrics custom metrics log data archive logs 1 2 custom metrics
  136. 136. #4 Logs und Metriken korrelieren / aggregieren Monitoring Best Practices AWS Cloud My Lambda logs log stream log data async sync Log Aggregator metrics custom metrics custom metrics log data archive logs 1 correlation ID custom metrics
  137. 137. #5 Logging via ENV Vars an Edge Server enablen/disablen Monitoring Best Practices AWS Cloud My Lambda logs log stream log data async sync Log Aggregator metrics custom metrics custom metrics log data archive logs DEBUG on/off ENV var 1 2 custom metrics
  138. 138. Schlussfolgerung: Spaß haben mit Serverless?
  139. 139. “Find suitable serverless workload and apply the correct integration patterns.”
  140. 140. ? ? ?
  141. 141. Lars Röwekamp, @mobileLarson Kontakt: lars.roewekamp@openknowledge.de kontakt@openknowledge.de Besten Dank! #WISSENTEILEN

×