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.

Embracing Serverless with Google

509 views

Published on

Tips and tricks to maximize performance and minimize serverless costs with Firebase and Google Cloud Functions. Live examples and analysis to show that GCF is the cheapest function provider, compared to Azure Functions and AWS Lambda.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Embracing Serverless with Google

  1. 1. Embracing Serverless w/ Google the Good, the Beta, and the Ugly Joseph Lust mabl engineer @lustcoder
  2. 2. “The secret of change is to focus all of your energy, not on fighting the old, but on building the new.” –Socrates
  3. 3. startups must push or perish 4
  4. 4. serverless just works ■ No Provisioning ■ Transparent Scaling ■ Event Driven ■ Pay only for Use 5
  5. 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
  6. 6. 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
  7. 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
  8. 8. function clarity through dashboards 9
  9. 9. live function health tracking 10
  10. 10. what about the competition? 11
  11. 11. costs: gcf vs the competition 12
  12. 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
  13. 13. costs vary by memory, cpu, & bandwidth 14 * Also see execution time, bandwidth, and memory costs
  14. 14. gcf cheapest due to free monthly allowances 15 * Also see execution time, bandwidth, and memory costs
  15. 15. 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
  16. 16. http://bit.ly/2vb2DHW 18 let’s test that autoscaling. traffic please
  17. 17. but, there are some speed bumps... 19
  18. 18. 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
  19. 19. 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
  20. 20. functions are not designed for failure* 22 * yet
  21. 21. functions require total trust 23
  22. 22. blazing fast function deployment 24
  23. 23. lossy pubsub deployments 25
  24. 24. work arounds to the rescue 26
  25. 25. 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
  26. 26. a few tips and tricks 28
  27. 27. 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
  28. 28. 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
  29. 29. 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
  30. 30. 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
  31. 31. so, in conclusion 33
  32. 32. embrace serverless ■ to focus on shipping code ■ to harness NodeJS microservices ■ to power low latency experiences ■ to provision, deploy, and scale automatically 34
  33. 33. 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
  34. 34. Questions?
  35. 35. decoupled async functions pattern 37

×