A Gentle Introduction to
Functions-as-a-Service
Valeri Karpov
@code_barbarian
github.com/vkarpov15
About Me
● Backend Lead @ Booster, Node.js OSS
● Core contributor for Mongoose, Mocha
● Blogger, thecodebarbarian.com
● Early employee at LevelUp, MongoDB, Booster
● Invented the MEAN stack
What’s This Talk About?
● The progression of dev-ops for startups
● Why FaaS is the next natural step for dev-ops
● Retaining state in “stateless” functions
● Trade-offs between different FaaS providers
2008: Physical Machine in Dorm Room
● EC2 was limited, other hosting services sucked
● LevelUp’s first release on an Ubuntu tower
○ Physical machines die or get shut down
○ Campus ISP is slow or changes the IP
○ Limited scale: shipping a new PC takes days
2012: Amazon EC2
● My next few startups all ran on 1-5 EC2 VMs
● Cloud VMs solve most physical machine issues
○ Power outages much less likely
○ Reliable internet maintained by Amazon
○ Spinning up a new VM takes minutes
2012: Amazon EC2
● Vanilla EC2 was great for single server apps
● But what about multiple app servers?
○ 2 services on the same VM in isolation
○ Continuous Deployment
○ Scaling horizontally with a click
2015: Containers and Orchestration
● Docker, Mesos, Kubernetes, etc.
● Compelling for CD and isolation
● Still Have Problems with Resource Usage
○ Memory limits per VM
○ Docker hogs disk space
Functions as a Service
● Instead of deploying an app, you deploy a
bunch of stateless functions
● No VMs, no OS updates
● Resource limits (RAM, CPU) per function call
● Functions run in response to triggers
API Gateways
● Cloud functions respond to triggers
● HTTP is a trigger, but what about:
○ API keys / auth
○ Rate limits
● FaaS providers have API Gateways for this
FaaS Providers
● Amazon AWS Lambda
● Microsoft Azure Functions
● Google Cloud Functions
● IBM Cloud Functions
● Oracle Cloud Fn
● LunchBadger, + many more
FaaS Open Source Libraries
● Kubeless
● OpenWhisk
● Fission
FaaS Advantages
● Easier to scale, no need to worry about too
much load on one service
● Cheaper for low-usage services
● Cheap and easy development environments
● Resource issues rare and easy to debug
FaaS Problems
● No strong best practices yet
● Completely different way of writing apps
● Limited language support
● Managing triggers and API Gateways
● Sometimes you want to retain state...
Why Retain State?
● Think about a persistent database connection
Stateless is a Big Performance Problem
● Connecting to a database on every function
call is slow
But You Can Retain Global State
● Put db handle in global scope
Common Trick Across FaaS Providers
● AWS Lambda: bit.ly/mongodb-lambda
● Azure Functions: bit.ly/mongodb-azure
○ Also With C#: bit.ly/csx-azure-state
● IBM Cloud: bit.ly/mongodb-ibm-cloud
Trade-offs Between Popular Providers
● AWS Lambda
● Azure Functions
● Google Cloud Functions
Size Restrictions
● Size limit per function (node_modules)
○ AWS Lambda: 50MB
○ Azure Functions: None (*)
○ Google Cloud: 100MB zipped, 500MB
unzipped
Primary Fee Structure
● AWS Lambda: $0.00001667 / GB-s, $0.20 / 1M
● Azure Functions: $0.000016 / GB-s, $0.20 / 1M
● Google Cloud: $0.0000025 / GB-s, $0.0000100
/ GHz-s
Hidden Fees: API Gateways
● AWS Lambda: $3.50 / 1M + data
● Azure Functions: no extra cost necessary
● Google Cloud Functions: no extra cost
necessary
Overall FaaS Recommendations
● Check out Azure Functions
● AWS Lambda and IBM Cloud are a mess
Further Reading
● My Blog:
○ bit.ly/mongodb-azure
○ bit.ly/mongodb-ibm-cloud
Thanks for Listening!

A Gentle Introduction to Functions-as-a-Service

  • 1.
    A Gentle Introductionto Functions-as-a-Service Valeri Karpov @code_barbarian github.com/vkarpov15
  • 2.
    About Me ● BackendLead @ Booster, Node.js OSS ● Core contributor for Mongoose, Mocha ● Blogger, thecodebarbarian.com ● Early employee at LevelUp, MongoDB, Booster ● Invented the MEAN stack
  • 3.
    What’s This TalkAbout? ● The progression of dev-ops for startups ● Why FaaS is the next natural step for dev-ops ● Retaining state in “stateless” functions ● Trade-offs between different FaaS providers
  • 4.
    2008: Physical Machinein Dorm Room ● EC2 was limited, other hosting services sucked ● LevelUp’s first release on an Ubuntu tower ○ Physical machines die or get shut down ○ Campus ISP is slow or changes the IP ○ Limited scale: shipping a new PC takes days
  • 5.
    2012: Amazon EC2 ●My next few startups all ran on 1-5 EC2 VMs ● Cloud VMs solve most physical machine issues ○ Power outages much less likely ○ Reliable internet maintained by Amazon ○ Spinning up a new VM takes minutes
  • 6.
    2012: Amazon EC2 ●Vanilla EC2 was great for single server apps ● But what about multiple app servers? ○ 2 services on the same VM in isolation ○ Continuous Deployment ○ Scaling horizontally with a click
  • 7.
    2015: Containers andOrchestration ● Docker, Mesos, Kubernetes, etc. ● Compelling for CD and isolation ● Still Have Problems with Resource Usage ○ Memory limits per VM ○ Docker hogs disk space
  • 8.
    Functions as aService ● Instead of deploying an app, you deploy a bunch of stateless functions ● No VMs, no OS updates ● Resource limits (RAM, CPU) per function call ● Functions run in response to triggers
  • 9.
    API Gateways ● Cloudfunctions respond to triggers ● HTTP is a trigger, but what about: ○ API keys / auth ○ Rate limits ● FaaS providers have API Gateways for this
  • 10.
    FaaS Providers ● AmazonAWS Lambda ● Microsoft Azure Functions ● Google Cloud Functions ● IBM Cloud Functions ● Oracle Cloud Fn ● LunchBadger, + many more
  • 11.
    FaaS Open SourceLibraries ● Kubeless ● OpenWhisk ● Fission
  • 12.
    FaaS Advantages ● Easierto scale, no need to worry about too much load on one service ● Cheaper for low-usage services ● Cheap and easy development environments ● Resource issues rare and easy to debug
  • 13.
    FaaS Problems ● Nostrong best practices yet ● Completely different way of writing apps ● Limited language support ● Managing triggers and API Gateways ● Sometimes you want to retain state...
  • 14.
    Why Retain State? ●Think about a persistent database connection
  • 15.
    Stateless is aBig Performance Problem ● Connecting to a database on every function call is slow
  • 16.
    But You CanRetain Global State ● Put db handle in global scope
  • 17.
    Common Trick AcrossFaaS Providers ● AWS Lambda: bit.ly/mongodb-lambda ● Azure Functions: bit.ly/mongodb-azure ○ Also With C#: bit.ly/csx-azure-state ● IBM Cloud: bit.ly/mongodb-ibm-cloud
  • 18.
    Trade-offs Between PopularProviders ● AWS Lambda ● Azure Functions ● Google Cloud Functions
  • 19.
    Size Restrictions ● Sizelimit per function (node_modules) ○ AWS Lambda: 50MB ○ Azure Functions: None (*) ○ Google Cloud: 100MB zipped, 500MB unzipped
  • 20.
    Primary Fee Structure ●AWS Lambda: $0.00001667 / GB-s, $0.20 / 1M ● Azure Functions: $0.000016 / GB-s, $0.20 / 1M ● Google Cloud: $0.0000025 / GB-s, $0.0000100 / GHz-s
  • 21.
    Hidden Fees: APIGateways ● AWS Lambda: $3.50 / 1M + data ● Azure Functions: no extra cost necessary ● Google Cloud Functions: no extra cost necessary
  • 22.
    Overall FaaS Recommendations ●Check out Azure Functions ● AWS Lambda and IBM Cloud are a mess
  • 23.
    Further Reading ● MyBlog: ○ bit.ly/mongodb-azure ○ bit.ly/mongodb-ibm-cloud
  • 24.