SlideShare a Scribd company logo
Serverless Apps on GCP
more dev, less ops
Joseph Lust mabl engineer @lustcoder
About Me: Joseph Lust
Engineer
■ Building the web for two decades
■ Cloud native since 2011
■ Currently building mabl ML cloud on GCP
■ Co-organizer GDG Cloud Boston Meetup
me@joelust.com
overview
■ Our serverless future
■ Serverless solutions GCP
■ Serverless demos
■ Taming serverless @ mabl
3
startups must push or perish
4
serverless just works
■ No Provisioning
■ Transparent Scaling
■ Event Driven
■ Pay only for Use
5
it’s all about opportunity cost
■ Provisioning takes time
■ Boilerplate takes time
■ You’re not running a hosting company
6
how developers deploy code
2014
2007 2013
VPS
Machine
Image
Docker
Containers
war File
AWS
Lambda
7
2000
Container Era
Serverless Era
Firebase
CF
Serverless functions
GCF
2016 2017
AF
exports.myService = (req, res) => res.send(‘hello world’);
mvf
es6+
other serverlessish GCP services
■ Serverless
▲ Scaling Clusters - Kubernetes Engine
▲ Kafka - Pub/Sub
▲ Mongo/EventSource - Firebase
▲ File Server - Cloud Storage
■ Not purely serverless, but close
▲ Tomcat/Jetty - App Engine
▲ Spark Streaming - Dataflow
9
Cloud
Pub/Sub
Cloud
Dataflow
Kubernetes
Engine
ML Engine
event driven all the way
■ Only run code on events
▲ Cloud Storage blob changes
▲ Pubsub message arrival
▲ HTTP endpoint requests
▲ DB/Auth/Conversion changes
■ No machines consuming 2% CPU all day
■ Very low latency operations
■ No more corn jobs!
10
exports.imageToJPG =
functions.storage.object().onFinalize(
async (object) => processImage()
);
example: image processor
es6+
but what do functions cost?
12
gcf is the cheapest function provider
Vendor FREE req/mo req/$
Google Cloud Functions 2M 5M
Firebase Cloud Functions 2M 2.5M
AWS Lambda 1M 5M
Azure Functions 1M 5M
13
See full details in Google Spreadsheet calculator
* Also see execution time, bandwidth, and memory costs
gcf cheapest counting free monthly allowances
14
* Also see execution time, bandwidth, and memory costs
gcf differentiators
■ Guaranteed CPU per memory allotment
■ Easy to use UI and tools
■ Stackdriver Logging & Error Reporting
Source: GCP Pricing, FB Pricing, AWS Lambda Pricing, Azure Pricing
15
Some quick demos
16
but, what about Microservices?
17
but, what about Micro Nanoservices?
18
microservices solve many pains
■ Minimize code size
▲ Can scale servers, not developers’ minds
■ Minimize deploy speed/code
■ Minimize blast radius
■ Decoupling, Coherence, Singleness of Purpose
19
how do you decouple services and handle discovery
■ We Don’t Do Discovery
■ Event Driven Queues
▲ HTTP endpoints for external services
▲ Blob change events for files
▲ Message queue events for everything else
■ No Daemons
▲ Don’t waste time spinning
20
decoupled async functions pattern
21
how do you handle changing microservice/models?
■ Versioned Payloads over the wire
▲ New service can handle older versions
■ Add Consumers, then Suppliers
■ Upgrade, don’t replace
■ Lazy read repair
▲ Pessimistic data upgrade and transform
▲ Upgrade path from old version
22
how do make slow deploys fast?
■ Multi-repo git layout
■ File change exclusion masks
■ Deploy functions in parallel
■ Harness CI & CD (e.g. Cloud Build)
23
how do you handle GCP outages?
■ Durable Pubsub subscriptions
■ No microservices on fast path
▲ Backend processing
▲ Keep the UI and lights on via Firebase
24
request costs round up
■ Requests billed per 100ms
■ Increments round up
■ Faster functions are not always cheaper
▲ 17ms → 100ms
▲ 101ms → 200ms
25
Run Time:
17ms
Billed Time: 100ms
Wasted
Time
minimizing your request costs
■ Batch multiple fast work units to fill the time (e.g. 100ms chunks)
26
Work Unit:
17ms
Billed Time: 100ms
Work Unit:
17ms
Work Unit:
17ms
Work Unit:
17ms
Work Unit:
17ms
Wasted
Time
minimizing your request costs
27
■ Use a middle man to shield file events from high memory loads
▲ Filter/light weight checks in middle man
▲ Send heavy lifting to larger function
■ Different inputs to same service have different resource needs
▲ e.g. 90% requests need 128MB ram, 10% need 512GB
▲ e.g. 80% requests complete in 30s, 20s take 2min
28
maximizing performance
■ Tune your CPU & Memory to the job
▲ Profile your microservices - CPU or memory bound?
■ More memory runs faster
▲ Greater CPU dedicated to larger memory allocation functions
▲ 128MB → 200 MHz
▲ 2048MB → 2.4GHz
▲ CPU/Memory costs increase linearly
■ Cache expensive objects between requests
▲ PubSub connections
▲ Firebase Admin instances
▲ Login tokens
29
but seriously, what’s this cost you?
30
track everything, from bits to cents
■ Metrics for every execution
▲ Every Byte of memory use
▲ Every Processor Cycle of runtime
▲ Every Byte of egress
▲ Every Invocation
■ Direct Billing to BigQuery export
▲ Easy to explore and query
▲ Easy to visualize with Data Studio
31
Real Production Numbers @ mabl
32
33
34
■ scaling to zero no longer important
■ you have a constant load
▲ Dedicated instance
when to move from Serverless to Servers
35
$
Load (rps)
Cloud Function
Dedicated
n1-standard-1
■ scaling to zero no longer important
■ you have dynamic load
▲ Kubernetes Deployment
▲ Knative function
▲ App Engine Service
when to move from Serverless to Servers
36
$
Load (rps)
Cloud FunctionKubernetes
Deployment
billing tips
■ Label functions on deploy
▲ Labels propagated to billing
▲ Can track Memory, CPU, Invocation, Ingress, Egress costs per function
■ Don’t forget the egress bandwidth
▲ Keep your data stores in the same region (Iowa)
▲ GCF only deployable to Iowa
37
gcloud beta functions deploy <your_fn> 
--labels=”app_name=<your_fn>” 
...
so, in conclusion
38
embrace serverless for
■ For low latency, event driven demands
■ For decoupled, cohesive, independent services
■ For painless deployment and auto-scaling
■ For reduced opex and oppex
39
(TL;DR) embrace serverless to
40
gcp serverless resources
■ FB CF Examples Repo: github.com/firebase/functions-samples
■ GCF Examples: github.com/GoogleCloudPlatform/nodejs-docs-samples
■ Jason Polites (great) Examples: github.com/jasonpolites/gcf-recipes
■ I/O 2018 CF Presentations
▲ Get Started Building Serverless Applications: youtu.be/JenJQ6gc14U
▲ Serverless on Google Cloud: youtu.be/iPQUdb0kssE
▲ Serverless Compute on Google Cloud: youtu.be/Y1sRy0Q2qig
▲ CI/CD in a Serverless World: youtu.be/iyGHW4UQ_Ts
▲ Building and Deploying Microservices: youtu.be/oALEthV9z_U
41
@lustcoder
Questions?

More Related Content

Serverless Apps on Google Cloud: more dev, less ops

  • 1. Serverless Apps on GCP more dev, less ops Joseph Lust mabl engineer @lustcoder
  • 2. About Me: Joseph Lust Engineer ■ Building the web for two decades ■ Cloud native since 2011 ■ Currently building mabl ML cloud on GCP ■ Co-organizer GDG Cloud Boston Meetup me@joelust.com
  • 3. overview ■ Our serverless future ■ Serverless solutions GCP ■ Serverless demos ■ Taming serverless @ mabl 3
  • 4. startups must push or perish 4
  • 5. serverless just works ■ No Provisioning ■ Transparent Scaling ■ Event Driven ■ Pay only for Use 5
  • 6. it’s all about opportunity cost ■ Provisioning takes time ■ Boilerplate takes time ■ You’re not running a hosting company 6
  • 7. how developers deploy code 2014 2007 2013 VPS Machine Image Docker Containers war File AWS Lambda 7 2000 Container Era Serverless Era Firebase CF Serverless functions GCF 2016 2017 AF
  • 8. exports.myService = (req, res) => res.send(‘hello world’); mvf es6+
  • 9. other serverlessish GCP services ■ Serverless ▲ Scaling Clusters - Kubernetes Engine ▲ Kafka - Pub/Sub ▲ Mongo/EventSource - Firebase ▲ File Server - Cloud Storage ■ Not purely serverless, but close ▲ Tomcat/Jetty - App Engine ▲ Spark Streaming - Dataflow 9 Cloud Pub/Sub Cloud Dataflow Kubernetes Engine ML Engine
  • 10. event driven all the way ■ Only run code on events ▲ Cloud Storage blob changes ▲ Pubsub message arrival ▲ HTTP endpoint requests ▲ DB/Auth/Conversion changes ■ No machines consuming 2% CPU all day ■ Very low latency operations ■ No more corn jobs! 10
  • 11. exports.imageToJPG = functions.storage.object().onFinalize( async (object) => processImage() ); example: image processor es6+
  • 12. but what do functions cost? 12
  • 13. gcf is the cheapest function provider Vendor FREE req/mo req/$ Google Cloud Functions 2M 5M Firebase Cloud Functions 2M 2.5M AWS Lambda 1M 5M Azure Functions 1M 5M 13 See full details in Google Spreadsheet calculator * Also see execution time, bandwidth, and memory costs
  • 14. gcf cheapest counting free monthly allowances 14 * Also see execution time, bandwidth, and memory costs
  • 15. gcf differentiators ■ Guaranteed CPU per memory allotment ■ Easy to use UI and tools ■ Stackdriver Logging & Error Reporting Source: GCP Pricing, FB Pricing, AWS Lambda Pricing, Azure Pricing 15
  • 17. but, what about Microservices? 17
  • 18. but, what about Micro Nanoservices? 18
  • 19. microservices solve many pains ■ Minimize code size ▲ Can scale servers, not developers’ minds ■ Minimize deploy speed/code ■ Minimize blast radius ■ Decoupling, Coherence, Singleness of Purpose 19
  • 20. how do you decouple services and handle discovery ■ We Don’t Do Discovery ■ Event Driven Queues ▲ HTTP endpoints for external services ▲ Blob change events for files ▲ Message queue events for everything else ■ No Daemons ▲ Don’t waste time spinning 20
  • 22. how do you handle changing microservice/models? ■ Versioned Payloads over the wire ▲ New service can handle older versions ■ Add Consumers, then Suppliers ■ Upgrade, don’t replace ■ Lazy read repair ▲ Pessimistic data upgrade and transform ▲ Upgrade path from old version 22
  • 23. how do make slow deploys fast? ■ Multi-repo git layout ■ File change exclusion masks ■ Deploy functions in parallel ■ Harness CI & CD (e.g. Cloud Build) 23
  • 24. how do you handle GCP outages? ■ Durable Pubsub subscriptions ■ No microservices on fast path ▲ Backend processing ▲ Keep the UI and lights on via Firebase 24
  • 25. request costs round up ■ Requests billed per 100ms ■ Increments round up ■ Faster functions are not always cheaper ▲ 17ms → 100ms ▲ 101ms → 200ms 25 Run Time: 17ms Billed Time: 100ms Wasted Time
  • 26. minimizing your request costs ■ Batch multiple fast work units to fill the time (e.g. 100ms chunks) 26 Work Unit: 17ms Billed Time: 100ms Work Unit: 17ms Work Unit: 17ms Work Unit: 17ms Work Unit: 17ms Wasted Time
  • 27. minimizing your request costs 27 ■ Use a middle man to shield file events from high memory loads ▲ Filter/light weight checks in middle man ▲ Send heavy lifting to larger function ■ Different inputs to same service have different resource needs ▲ e.g. 90% requests need 128MB ram, 10% need 512GB ▲ e.g. 80% requests complete in 30s, 20s take 2min
  • 28. 28
  • 29. maximizing performance ■ Tune your CPU & Memory to the job ▲ Profile your microservices - CPU or memory bound? ■ More memory runs faster ▲ Greater CPU dedicated to larger memory allocation functions ▲ 128MB → 200 MHz ▲ 2048MB → 2.4GHz ▲ CPU/Memory costs increase linearly ■ Cache expensive objects between requests ▲ PubSub connections ▲ Firebase Admin instances ▲ Login tokens 29
  • 30. but seriously, what’s this cost you? 30
  • 31. track everything, from bits to cents ■ Metrics for every execution ▲ Every Byte of memory use ▲ Every Processor Cycle of runtime ▲ Every Byte of egress ▲ Every Invocation ■ Direct Billing to BigQuery export ▲ Easy to explore and query ▲ Easy to visualize with Data Studio 31
  • 33. 33
  • 34. 34
  • 35. ■ scaling to zero no longer important ■ you have a constant load ▲ Dedicated instance when to move from Serverless to Servers 35 $ Load (rps) Cloud Function Dedicated n1-standard-1
  • 36. ■ scaling to zero no longer important ■ you have dynamic load ▲ Kubernetes Deployment ▲ Knative function ▲ App Engine Service when to move from Serverless to Servers 36 $ Load (rps) Cloud FunctionKubernetes Deployment
  • 37. billing tips ■ Label functions on deploy ▲ Labels propagated to billing ▲ Can track Memory, CPU, Invocation, Ingress, Egress costs per function ■ Don’t forget the egress bandwidth ▲ Keep your data stores in the same region (Iowa) ▲ GCF only deployable to Iowa 37 gcloud beta functions deploy <your_fn> --labels=”app_name=<your_fn>” ...
  • 39. embrace serverless for ■ For low latency, event driven demands ■ For decoupled, cohesive, independent services ■ For painless deployment and auto-scaling ■ For reduced opex and oppex 39
  • 41. gcp serverless resources ■ FB CF Examples Repo: github.com/firebase/functions-samples ■ GCF Examples: github.com/GoogleCloudPlatform/nodejs-docs-samples ■ Jason Polites (great) Examples: github.com/jasonpolites/gcf-recipes ■ I/O 2018 CF Presentations ▲ Get Started Building Serverless Applications: youtu.be/JenJQ6gc14U ▲ Serverless on Google Cloud: youtu.be/iPQUdb0kssE ▲ Serverless Compute on Google Cloud: youtu.be/Y1sRy0Q2qig ▲ CI/CD in a Serverless World: youtu.be/iyGHW4UQ_Ts ▲ Building and Deploying Microservices: youtu.be/oALEthV9z_U 41 @lustcoder