Serverless Patterns

A presentation at Serverless Seattle Meetup in April 2019 in Seattle, WA, USA by Jesse Butler

Slide 1

Slide 1

ive Serverless Patterns Design and Use Patterns in Serverless Jesse Butler Cloud Developer Advocate, Oracle Cloud Infrastructure cloudnative.oracle.com @jlb13

Slide 2

Slide 2

Level Set • Roles in the room? • Serverless users? • In production? • Lambda? Azure? Something Else? Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 2

Slide 3

Slide 3

Monolithic Applications Users Application Database Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 4

Slide 4

Monolithic Applications Users Application Database Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 5

Slide 5

Virtualization and Consolidation Abstractions Containers Virtual machines Bare Metal To the Cloud Decreasing concern (and control) over infrastructure implementation Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 5

Slide 6

Slide 6

Microservices Deploying Code to Systems We Build in the Cloud with Containers and Kubernetes Load balancer Service Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Service Service Database Queue @jlb13

Slide 7

Slide 7

Serverless Deploying Code to Systems We Build in the Cloud with Containers and Kubernetes Load balancer Service Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Service Service Database Queue @jlb13

Slide 8

Slide 8

Trend towards Serverless Functions Abstractions Containers Virtual machines Bare Metal To the Cloud Infrastructure implementation and maintenance responsibility Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 8

Slide 9

Slide 9

Serverless is a Spectrum Container Orchestration Kubernetes Nomad Docker Swarm Ideally managed, but still infrastructure you care about Fully aware Container Services ECS, Fargate Azure CS GCP Cloud Run DIY FaaS OpenFaaS Fn Project Managed service provision containers, abstracts infrastructure you care about Leverage container management system under the covers, introduce Functions architecture Awareness of infrastructure Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Managed Serverless AWS Lambda Azure Functions Google Functions Oracle Functions Fully managed platform for hosting and executing code Invisible @jlb13 9

Slide 10

Slide 10

Containers are the new Process Model, Right? Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 10

Slide 11

Slide 11

Containers are the new Process Model, Right? Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 11

Slide 12

Slide 12

Don’t Conflate Requirements with Complexity Aversion Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 12

Slide 13

Slide 13

What Is Serverless • Event-driven architecture • Invisible infrastructure • Automatic scaling on demand • Granular billing for execution time • Fault tolerant and highly available Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 13

Slide 14

Slide 14

Serverless Deployment, the Duck Test Upload Function Source Code Configure Function Trigger Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Function is invoked when triggered Pay for execution time, not idle time @jlb13 14

Slide 15

Slide 15

Serverless is Not Really a Spectrum Container Orchestration Kubernetes Nomad Docker Swarm Ideally managed, but still infrastructure you care about Fully aware Container Services ECS, Fargate Azure CS GCP Cloud Run DIY FaaS OpenFaaS Fn Project Managed service provision containers, abstracts infrastructure you care about Leverage container management system under the covers, introduce Functions architecture Awareness of infrastructure Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Managed Serverless AWS Lambda Azure Functions Google Functions Oracle Functions Fully managed platform for hosting and executing code Invisible @jlb13 15

Slide 16

Slide 16

What Is Serverless, Distilled Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 16

Slide 17

Slide 17

What Is Serverless Not • It’s not magic, it’s a choice • Brownfield: You need to break the monolith apart regardless • Greenfield: You need a solid design • Nothing is free Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 17

Slide 18

Slide 18

Hype Cycle – Productive Adoption Cloud Computing Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 19

Slide 19

Hype Cycle – Serverless in Waves Serverless Computing Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 20

Slide 20

Get Through This Quickly… Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 21

Slide 21

…And Get Here Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 22

Slide 22

Serverless From 30k Feet Event Sources Function Execution F(n) F(n) F(n) Backend Services F(n) Kubernetes, Docker, and/or Hypervisor Business Intelligence Analytics Triggers Compute, Network, Storage Databases Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13 22

Slide 23

Slide 23

Function Example • Different projects and products differ in use and workflow • Just the code, configured against any number of event triggers • Basically follow microservices rules of engagement • As with microservices, applications are composed of many functions Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 24

Slide 24

Events and Execution Models • Events are driven by context • Execution model is your choice Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 25

Slide 25

Events, Determined by Context • Changes in data • API Invocations • Requests on endpoints • Changes in resources • Timers, Alarms, Direct Invocation… Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 26

Slide 26

Using Events • Events are configured differently per platform • Inform the platform as to what event(s) should invoke this function • Function can consume the event and do the things • CNCF Serverless WG has drafted a CloudEvents specification Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 27

Slide 27

Execution Models • Synchronous • Asynchronous • Streaming Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 28

Slide 28

Error Handling by Model • Synchronous –Calling code handles the error • Asynchronous –System retries based upon timeline • Streaming –System retries based upon data efficacy Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 29

Slide 29

What Can We Build With Serverless? • Web and Mobile Backends • Any other backend API implementations • Real-time Processing of Files, Streams • Batch Processing • Glueing up SaaS things • Kind of anything Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 30

Slide 30

Web and Mobile Backends Identity Database API Platform Web, Mobile Apps Functions Mobile Trigger functions Process data Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Storage Data persisted @jlb13 30

Slide 31

Slide 31

Extend and Enhance Existing Applications SaaS App Inventory create / update Analytics Functions Another App Support incident create / update Trigger functions Enrich data and send to Analytics service Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Use data for analytics and insights Visualize data @jlb13 31

Slide 32

Slide 32

Real-Time Stream Processing Messaging/ Streaming Database Functions Data from multiple sources – Product Reviews and Ratings, Customer Service Interactions, Social Media, etc. Trigger functions Perform user sentiment analysis Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Records saved in database Dashboards with user sentiment analysis trends @jlb13 32

Slide 33

Slide 33

Real-Time File Processing Database Storage Functions High resolution product image uploaded to storage Trigger functions Generate images of different resolutions and sizes Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Storage Images saved in Storage, metadata in Database Generated images displayed on various pages and devices @jlb13 33

Slide 34

Slide 34

Internet of Things Executive Dashboard Service Cloud Ingest Functions Devices and things streaming sensor data Trigger functions Check data against thresholds. If exceeded, raise support incidents, send notifications Copyright © 2019, Oracle and/or its affiliates. All rights reserved. Mobile Incident created in Service Cloud, notification sent to the technician Technician App @jlb13 34

Slide 35

Slide 35

Batch Processing Scheduled batch job Database Database Functions Credit card transactions Transaction details Calculate bonus points Bonus points updated Loyalty bonus received Scheduled batch job Database Storage Functions Utility consumption Consumption details Generate utility bill PDF file Copyright © 2019, Oracle and/or its affiliates. All rights reserved. PDF files saved in Storage Utility bill PDF file @jlb13 35

Slide 36

Slide 36

DevOps Automation Compute Storage Other

Check tags Check security roles Patch or update Modify/kill resource Vulnerability assess Check for idle State Change or a Timer Copyright © 2019, Oracle and/or its affiliates. All rights reserved. … @jlb13 36

Slide 37

Slide 37

Big Ideas Around the Code • Don’t own what you don’t have to • Serverless is all about APIs • When you do implement, simplify • Plan ahead for observability Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 38

Slide 38

Choose a Pattern that Helps you Minimize • Less is more: shoot for a single handler per module • If one function does more than one discrete thing, break it up • Better to proliferate than to decompensate • Observability and triage become infinitely easier at the boundaries Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 39

Slide 39

Separate and Simplify • Simplify application estate as well • Events can and probably should define application boundaries • Share libraries between functions and applications, not execution context Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 40

Slide 40

Code Reuse • Not long ago, Serverless function deployments were zip files • Now, many Serverless platforms expose a container image to you • Others use layering which mimics the container image stacking Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 41

Slide 41

Observability • Metrics – Aggregate data regarding the behavior of a thing over time • Tracing – Instrumentation which provides an instance of an action, traversing the entire stack • Logging – Developer breadcrumbs we leave to give context for a certain code path Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 42

Slide 42

Triaging Issues • Monolith in a VM – log into the host, look at logs, run a debugger • Containers in Kubernetes – Istio, Jaeger, Prometheus, Grafana, et al • Serverless… is complicated. Logging is there, but that’s not very useful at scale • OpenTracing & Jaeger is a possibility Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 43

Slide 43

Observability Solutions From Your Provider Cloudwatch, X-ray, Stackdriver, OCI Monitoring and Logging, Azure Insights, IBM Monitoring, and others Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 44

Slide 44

Observability Solutions From Other Experts Honeycomb, IO|Pipe, DataDog, Dashbird, Thundra, Epsagon, Splunk, Lightstep, Solo, and others (sorry if I missed yours!) Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 45

Slide 45

Use Services and SaaS When Possible • DBaaS • Identity, Auth, Forms • Storage Services • Email, SMS • Maps, GPS • Media Streaming • Chat and Chatbots Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 46

Slide 46

Worries • Don’t worry too much about cold starts • Do worry about data egress and migration • Pay attention to the system you are integrating with, keep it open if possible Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 47

Slide 47

Is Serverless Simpler? • In a word, no • But that doesn’t mean it’s not better • Serverless doesn’t really mean less complexity • Resolving complexity is generally directly related to your core business Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 48

Slide 48

Is Serverless Better? • In a word, yes • Less toil in deployment and maintenance of systems is beneficial to focus • OpEx reductions can be profound • Tradeoff: we depend upon third parties to address issues as they arise Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 49

Slide 49

Final Thoughts • Put Serverless on your radar – Greenfield – Brownfield migration • Often a POC becomes production • Resist the urge to compare DevOps and Serverless. Apples to Apple Pie. • Build stuff! Copyright © 2019, Oracle and/or its affiliates. All rights reserved. @jlb13

Slide 50

Slide 50

Thanks! @jlb13 cloud.oracle.com/trial cloudnative.oracle.com