1 of 54

Serverless Computing

What, why, why not and how?

Harald Kubota harald.kubota@gmail.com

July 2017

2 of 54

Index

  • Definitions of IaaS, PaaS, FaaS
  • #Serverless #NoOps
  • What is a “Function”?
  • Functions and Applications
  • When to use FaaS?
  • Example - Prime Counting Microservice
  • Costs Comparison
  • Appendix

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

3 of 54

Definitions

IaaS - Infrastructure as a Service

PaaS - Platform as a Service

FaaS - Functions as a Service (Serverless Computing)

Another “Serverless Computing” Definition

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

4 of 54

IaaS - Don’t Worry About Hardware Details

Hardware: CPU, RAM, Disks

Network: Cables, Switches, Routers

OS

Libraries

Run-Time environment

Service

Red Hat RHEL7.2 / Windows 2012 R2

translator.py

Apache, IIS

Virtual Machine

4 vCPUs, 16 GB RAM, 200GB Disks (RAID 1)

Application

Python 3.6.1, SQLAlchemy library, MySQL 5.7.18

HP ProLiant DL580 Gen 9, Intel E7-4800, 256GB RAM, SmartArray P440 RAID Controller, 4 600GB SAS disks, SolarFlare Flareon Ultra SFN8542

Blue: User is responsible for running it

Gray: Service provider is responsible for provisioning and running it

5 of 54

IaaS Examples

6 of 54

Managed Server - Don’t Worry About OS Details Either

Hardware: CPU, RAM, Disks

Network: Cables, Switches, Routers

OS

Libraries

Run-Time environment

Service

Red Hat RHEL7 / Windows 2012 R2

translator.py

Apache, IIS

Virtual Machine

4 vCPUs, 16 GB RAM, 200 GB Disks (RAID 1)

Application

Python 3.6.1, SQLAlchemy library, MySQL 5.7.18

HP ProLiant DL580 Gen 9, Intel E7-4800, 256GB RAM, SmartArray P440 RAID Controller, 4 600GB SAS disks, SolarFlare Flareon Ultra SFN8542

7 of 54

PaaS - Concentrate on the Code

Hardware: CPU, RAM, Disks

Network: Cables, Switches, Routers

OS

Libraries

Service

Red Hat RHEL7 / Windows 2012 R2

translator.py

Apache, IIS

Virtual Machine

4 vCPUs, 16 GB RAM, 200 GB Disks (RAID 1)

Application

SQLAlchemy library

Python 3.6, MySQL 5

HP ProLiant DL580 Gen 9, Intel E7-4800, 256GB RAM, SmartArray P440 RAID Controller, 4 600GB SAS disks, SolarFlare Flareon Ultra SFN8542

Run-Time Environment

8 of 54

PaaS Examples

9 of 54

FaaS - Concentrate on the Function

Hardware: CPU, RAM, Disks

Network: Cables, Switches, Routers

OS

Libraries

Service

Red Hat RHEL7 / Windows 2012 R2

translator.py

Apache, IIS

Virtual Machine

4 vCPUs, 16 GB RAM, 200 GB Disks (RAID 1)

Application

SQLAlchemy library

Python 3.6, MySQL 5

HP ProLiant DL580 Gen 9, Intel E7-4800, 256GB RAM, SmartArray P440 RAID Controller, 4 600GB SAS disks, SolarFlare Flareon Ultra SFN8542

Run-Time Environment

User connects here

10 of 54

FaaS Examples

11 of 54

Another “Serverless Computing” Definition

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

12 of 54

Another “Serverless Computing” Definition

Code that runs on event-driven, ephemeral and stateless environments,

fully managed by a third-party.

��https://cheesecakelabs.com/blog/what-is-serverless-all-about/

The program code, incl. libraries needed

Triggered by something (incoming request or message)

Every time you call the code, a new environment is being spun up and it’s deleted afterwards

No state and no local methods/storage to keep a state

Nothing for you to do. Nothing you can do.

13 of 54

How does it work internally?

  1. You store your code on the provider side (e.g. AWS Lambda)
  2. You define the trigger when it shall be executed
  3. When it needs to be executed, the provider will:
    1. Build a server
    2. Take your code
    3. Deploy your code into the server
    4. Run your code
    5. Return the result
    6. Destroy the server

For efficiency reasons, replace “server” with “container”

14 of 54

What is a “State”?

  • Stateful examples
    • Your balance of your bank account: get_balance(bank_account_number)
    • The date() function

  • Stateless example:
    • Doubling numbers: double(number)

15 of 54

Functions

Applications

Definitions

Serverless and NoOps

When to use FaaS

Costs

Appendix

Example

16 of 54

Serverless = No Servers?

No Servers = No Ops?

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

17 of 54

#Serverless #NoOps

Welcome to the serverless fairyland!

It’s a dream come true!

Serverless = No servers to worry about!

No more Ops!

Mipsytipsy, https://charity.wtf/2016/05/31/wtf-is-operations-serverless/

18 of 54

19 of 54

#Serverless #YesOps

  • Core competencies of Operations Engineering
    • Scalability
    • Resiliency
    • Availability
    • Maintainability
    • Security
    • Simplicity in complex systems
    • Instrumentation and visibility
    • Graceful degradation
  • But: SysAdmin done by Provider

20 of 54

What is the “F” in “FaaS”?

What is a “Function”?

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

21 of 54

What is a Function? - Context: Mathematics

Note that the function f: does not have any state

22 of 54

What is a Function? - Context: Web

Trigger

HTTP GET request to http://translate.com/translate

Input

HTTP GET http://translate.com/translate?in=en&out=de&text=Good%20Morning

Output

“Guten Morgen”

23 of 54

But where is my Application?

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

24 of 54

Many Functions Become the Application

2 functions in a very simple translation web site:

  • Display Initial Page
    1. Input: HTTP GET request for http://translate.com/
    2. Output: A web page with a form
  • Translate Text
    • Input: HTTP POST FORM request with text and target language
    • Output: Translated text

25 of 54

Demo Time!

Example:

Translation Web Page

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

26 of 54

Keeping a State

To keep a state, a FaaS function needs to store it somewhere permanently.

Example:

  • Counting users of a web page

Typical choices are:

  • Database
  • External Storage (e.g. S3 buckets)
  • Not possible: Local filesystem (because of ephemeral environment)

27 of 54

When to use FaaS?

Definitions

Serverless and NoOps

Functions

Applications

When to use FaaS

Costs

Appendix

Example

28 of 54

When to use FaaS?

What works well for FaaS?

  • Scalability from 0 to web scale
  • Stateless Microservices
  • Event based Processing

What does not work well for FaaS?

  • Persistent connections (to client or to back-end)
  • Long startup times

Possible Triggers/Events

  • HTTP requests GET, PUT, POST, etc.
  • Storage updates (e.g. user uploaded a file)
  • Messaging (PubSub, SNS)
  • Time/Intervals
  • ...

29 of 54

Example: Google Cloud Functions

Microservice: Counting Primes

Definitions

Serverless and NoOps

Functions

Applications

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

Example

30 of 54

Google Cloud Functions

  • Start from scratch

31 of 54

GC: New Project

  • Create a new project
  • All permissions and objects are owned by one project

32 of 54

GC: Storage

  • Need a bucket to store functions

33 of 54

GC: Storage

  • Name of the bucket (globally unique)
  • Storage Class
  • Storage Location

34 of 54

GC: Functions

  • Create a new function

35 of 54

Example: GC Counting Primes

Creating a new function

  • Name
  • Uses HTTP trigger
  • Shows the URL to use

36 of 54

Example: GC Counting Primes

  • Source code (index.js)
  • Stage bucket is where the function will be stored temporarily
  • Function to call (=exported function)

37 of 54

Example: GC Counting Primes

Function primeCount created:

38 of 54

Example: GC Counting Primes

Calling it from any machine via cURL

or via a web browser

39 of 54

Example: GC Counting Primes - Statistics

40 of 54

The Source Code

11: exported and called function

12-24: Prime calculation

25: Get URL param named “limit”

27: Output data format

28: HTTP 200 return code

28: Return JSON

29-31: Return limit, and number of primes and primes themselves

41 of 54

Code Differences between

GCF and AWS Lambda

Definitions

Serverless and NoOps

Functions

Applications

GC vs AWS Example

Costs

When to use FaaS

Good and Bad

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

GCF vs Lambda

42 of 54

Code - GC Functions vs AWS Lambda

43 of 54

Example: Google Cloud

Microservice: Tic Tac Toe

Definitions

Serverless and NoOps

Functions

Applications

AWS Example

Costs

When to use FaaS

Good and Bad

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

Example

44 of 54

Example: GC Tic Tac Toe

Calling it from any machine via cURL

or via a web browser (with a bit of HTML)

45 of 54

Build your own FaaS:

OpenWhisk

or

http://docs.get-faas.com/

Definitions

Serverless and NoOps

Functions

Applications

OpenWhisk

get-faas

Costs

When to use FaaS

Good and Bad

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

DIY FaaS

46 of 54

OpenWhisk (Apache Incubator)

47 of 54

http://docs.get-faas.com/

48 of 54

A Real Use-Case:

https://acloud.guru/

Definitions

Serverless and NoOps

Functions

Applications

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

Example

49 of 54

A Real Example: A Cloud Guru

Training platform for cloud training.

More details: Serverless - Cloud functions and the future of software architecture

50 of 54

Costs Comparison

AWS Lambda

vs

GC Functions

Definitions

Serverless and NoOps

Functions

Applications

GC Example

Costs

When to use FaaS

Good and Bad

When to use FaaS

Costs

Appendix

Example

51 of 54

Costs - AWS Lambda vs Google Cloud Functions

AWS Lambda

  • Free per month: 1M requests and 400,000 GB*s free

  • Requests: $ 0.20 per 1 M requests thereafter

  • $ 16.67 for 1 M GB-second used (100ms resp. MB resolution)

  • Plus data transfer

Google Cloud Functions

  • Free per month: 2M requests and 400,000 GB*s, 200,000 GHz*s free

  • Requests: $ 0.40 per 1 M requests thereafter

  • $ 2.5 for 1 M GB-second used (100ms resp. MB resolution)

  • $ 10.0 per 1M GHz-second

  • Plus data transfer

52 of 54

Costs - AWS Lambda vs Google Cloud Functions

AWS Lambda

  • 3 M requests, 0.5 GB RAM, 0.4 s
  • Requests: 3 M - 1 M = $ 0.40
  • GB*s: 3 M * 0.5 GB * 0.4 s = $ 3.34
  • Total: $ 3.74

  • 100 M requests, 0.5 GB RAM, 0.4 s
  • Requests: 100 M - 1 M = $ 19.8
  • GB*s: 100 M * 0.5 GB * 0.4 s = $ 326.73
  • Total: $ 346.53

Google Cloud Functions

  • 3 M requests, 0.5 GB RAM, 0.4 s
  • Requests: 3 M - 2 M = $ 0.40
  • GB*s: 3 M * 0.5 GB * 0.4 s = $ 1.50
  • GHz*s: 3 M * 0.8 GHz * 0.4 s = $ 2.80
  • Total: $ 4.70

  • 100 M requests, 0.5 GB RAM, 0.4 s
  • Requests: 100 M - 2 M = $ 39.2
  • GB*s: 100 M * 0.5 GB * 0.4 s = $ 49
  • GHz*s: 100 M * 0.5 GB * 0.4 s = $ 198
  • Total: $ 286.20

53 of 54

Definitions

p3

Serverless and NoOps

p16

Functions

p20

Applications

p23

When to use FaaS

p27

Example

p29, p41, p43, p45, p48

Costs

p50

The End

Appendix

p54

54 of 54

Appendix

GitHub repo of the used examples:

https://github.com/haraldkubota/faas-examples