Embracing Serverless w/ Google
the Good, the Beta, and the Ugly
Joseph Lust mabl engineer @lustcoder
“The secret of change is to focus all of your
energy, not on fighting the old, but on building
the new.”
–Socrates
startups must push or perish
4
serverless just works
■ No Provisioning
■ Transparent Scaling
■ Event Driven
■ Pay only for Use
5
how developers deploy code
2014
2007 2013
VPS
Machine
Image
Docker
Containers
war File
AWS
Lambda
6
2000
Container Era
Serverless Era
Firebase
CF
Serverless functions
GCF
2016 2017
AF
event driven all the way
Trigger Events Firebase CF GCF
Cloud Storage Events ✔ ✔
PubSub Topics ✔ ✔
HTTP Endpoint ✔ ✔
Auth Events ✔ ✘
Database Events ✔ ✘
Google Analytics Events ✔ ✘
7
google function offerings have different features
Features Firebase CF GCF
Stackdriver Error Reports ✔ ✔
Cloud Logging ✔ ✔
Environment Configs ✔ ✘
Code Based Wireup ✔ ✘
Rich Function Dashboard ✘ ✔
Deployment Wireup ✘ ✔
SCM Base Deploy ✘ ✔
8
function clarity through dashboards
9
live function health tracking
10
what about the competition?
11
costs: gcf vs the competition
12
google 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
costs vary by memory, cpu, & bandwidth
14
* Also see execution time, bandwidth, and memory costs
gcf cheapest due to free monthly allowances
15
* Also see execution time, bandwidth, and memory costs
gcf differentiators
■ Largest possible function memory: 2 GBytes
■ Guaranteed CPU per memory allotment
■ Node first focus
■ Easy to use UI and tools
■ Stackdriver Logging & Error Reporting
Source: GCP Pricing, FB Pricing, AWS Lambda Pricing, Azure Pricing
16
http://bit.ly/2vb2DHW
18
let’s test that autoscaling. traffic please
but, there are some speed bumps...
19
the ugly: firebase cloud functions
■ All functions run as FB project Editor
■ No failure retry semantics
■ Cannot access resources cross project
■ CLI deploy requires rigid project layout
■ Automatic undeploy of all functions for non-standard layouts
■ Slow deployment ~ 5min
20
the uglier: gcf
■ Cannot pass configs to function
■ No failure retry semantics
■ All functions run as project Editor
■ Complex multi-module deploy
▲ Impossible from SCM deploy
■ Slow deployment ~ 2min
■ Non-Deterministic Deployment Failures
■ Single Supported Region (Iowa US-Centra1)
21
functions are not designed for failure*
22
* yet
functions require total trust
23
blazing fast function deployment
24
lossy pubsub deployments
25
work arounds to the rescue
26
work around the warts
■ Load ServiceAccount key from KMS encrypted CS file
■ Cache resources between function calls
■ Use Firebase Admin lib from GCF
▲ Best of most worlds
■ Use the lowest sensible memory and timeout limits
■ Use --local-path and --include-ignored-files for multi-module deploy
27
a few tips and tricks
28
request costs round up
■ Requests billed per 100ms
■ Increments round up
■ Faster functions are not always cheaper
▲ 17ms → 100ms
▲ 101ms → 200ms
29
Run Time:
17ms
Billed Time: 100ms
Wasted
Time
minimizing your request costs
■ Cache connections, tokens, services between requests
■ Minimize Memory footprint
▲ Defaults to 256MB, will 128MB do?
■ Minimize Timeout to fail fast, retry
▲ Defaults to 60s, will 30s work?
▲ Find request timeout curve, note fast fail, low likelihood
30
minimizing your request costs
■ Batch multiple fast work units to fill the time (e.g. 100ms chunks)
31
31
Work Unit:
17ms
Billed Time: 100ms
Work Unit:
17ms
Work Unit:
17ms
Work Unit:
17ms
Work Unit:
17ms
Wasted
Time
maximizing performance
■ 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
32
so, in conclusion
33
embrace serverless
■ to focus on shipping code
■ to harness NodeJS microservices
■ to power low latency experiences
■ to provision, deploy, and scale automatically
34
google cloud serverless resources
■ FB CF Examples Repo: github.com/firebase/functions-samples
■ GCF Examples: github.com/GoogleCloudPlatform/nodejs-docs-samples
■ Jason Polites Examples: github.com/jasonpolites/gcf-recipes
■ I/O 2017 CF Presentations
▲ Building the Fire!sale demo app: youtu.be/G-MBeEW92v4
▲ FB and ML with CF: youtu.be/RdqV_N0sCpM
▲ FB CF and Testability: youtu.be/SnWwkURpwxs
▲ Data Pipelines with CF: youtu.be/guo-4IOqx2M
35
@lustcoder
Questions?
decoupled async functions pattern
37

Embracing Serverless with Google

  • 1.
    Embracing Serverless w/Google the Good, the Beta, and the Ugly Joseph Lust mabl engineer @lustcoder
  • 3.
    “The secret ofchange is to focus all of your energy, not on fighting the old, but on building the new.” –Socrates
  • 4.
    startups must pushor perish 4
  • 5.
    serverless just works ■No Provisioning ■ Transparent Scaling ■ Event Driven ■ Pay only for Use 5
  • 6.
    how developers deploycode 2014 2007 2013 VPS Machine Image Docker Containers war File AWS Lambda 6 2000 Container Era Serverless Era Firebase CF Serverless functions GCF 2016 2017 AF
  • 7.
    event driven allthe way Trigger Events Firebase CF GCF Cloud Storage Events ✔ ✔ PubSub Topics ✔ ✔ HTTP Endpoint ✔ ✔ Auth Events ✔ ✘ Database Events ✔ ✘ Google Analytics Events ✔ ✘ 7
  • 8.
    google function offeringshave different features Features Firebase CF GCF Stackdriver Error Reports ✔ ✔ Cloud Logging ✔ ✔ Environment Configs ✔ ✘ Code Based Wireup ✔ ✘ Rich Function Dashboard ✘ ✔ Deployment Wireup ✘ ✔ SCM Base Deploy ✘ ✔ 8
  • 9.
  • 10.
  • 11.
    what about thecompetition? 11
  • 12.
    costs: gcf vsthe competition 12
  • 13.
    google is thecheapest 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.
    costs vary bymemory, cpu, & bandwidth 14 * Also see execution time, bandwidth, and memory costs
  • 15.
    gcf cheapest dueto free monthly allowances 15 * Also see execution time, bandwidth, and memory costs
  • 16.
    gcf differentiators ■ Largestpossible function memory: 2 GBytes ■ Guaranteed CPU per memory allotment ■ Node first focus ■ Easy to use UI and tools ■ Stackdriver Logging & Error Reporting Source: GCP Pricing, FB Pricing, AWS Lambda Pricing, Azure Pricing 16
  • 18.
    http://bit.ly/2vb2DHW 18 let’s test thatautoscaling. traffic please
  • 19.
    but, there aresome speed bumps... 19
  • 20.
    the ugly: firebasecloud functions ■ All functions run as FB project Editor ■ No failure retry semantics ■ Cannot access resources cross project ■ CLI deploy requires rigid project layout ■ Automatic undeploy of all functions for non-standard layouts ■ Slow deployment ~ 5min 20
  • 21.
    the uglier: gcf ■Cannot pass configs to function ■ No failure retry semantics ■ All functions run as project Editor ■ Complex multi-module deploy ▲ Impossible from SCM deploy ■ Slow deployment ~ 2min ■ Non-Deterministic Deployment Failures ■ Single Supported Region (Iowa US-Centra1) 21
  • 22.
    functions are notdesigned for failure* 22 * yet
  • 23.
  • 24.
    blazing fast functiondeployment 24
  • 25.
  • 26.
    work arounds tothe rescue 26
  • 27.
    work around thewarts ■ Load ServiceAccount key from KMS encrypted CS file ■ Cache resources between function calls ■ Use Firebase Admin lib from GCF ▲ Best of most worlds ■ Use the lowest sensible memory and timeout limits ■ Use --local-path and --include-ignored-files for multi-module deploy 27
  • 28.
    a few tipsand tricks 28
  • 29.
    request costs roundup ■ Requests billed per 100ms ■ Increments round up ■ Faster functions are not always cheaper ▲ 17ms → 100ms ▲ 101ms → 200ms 29 Run Time: 17ms Billed Time: 100ms Wasted Time
  • 30.
    minimizing your requestcosts ■ Cache connections, tokens, services between requests ■ Minimize Memory footprint ▲ Defaults to 256MB, will 128MB do? ■ Minimize Timeout to fail fast, retry ▲ Defaults to 60s, will 30s work? ▲ Find request timeout curve, note fast fail, low likelihood 30
  • 31.
    minimizing your requestcosts ■ Batch multiple fast work units to fill the time (e.g. 100ms chunks) 31 31 Work Unit: 17ms Billed Time: 100ms Work Unit: 17ms Work Unit: 17ms Work Unit: 17ms Work Unit: 17ms Wasted Time
  • 32.
    maximizing performance ■ Morememory 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 32
  • 33.
  • 34.
    embrace serverless ■ tofocus on shipping code ■ to harness NodeJS microservices ■ to power low latency experiences ■ to provision, deploy, and scale automatically 34
  • 35.
    google cloud serverlessresources ■ FB CF Examples Repo: github.com/firebase/functions-samples ■ GCF Examples: github.com/GoogleCloudPlatform/nodejs-docs-samples ■ Jason Polites Examples: github.com/jasonpolites/gcf-recipes ■ I/O 2017 CF Presentations ▲ Building the Fire!sale demo app: youtu.be/G-MBeEW92v4 ▲ FB and ML with CF: youtu.be/RdqV_N0sCpM ▲ FB CF and Testability: youtu.be/SnWwkURpwxs ▲ Data Pipelines with CF: youtu.be/guo-4IOqx2M 35 @lustcoder
  • 36.
  • 37.