Serverless: “Pay as You Go”

By: Dr. Maria Seraphina Astriani

 

Do you want to save money when your server is idle?

Try SERVERLESS!

 

What is serverless computing?

Serverless computing enables developers to build applications faster by eliminating the need for them to manage infrastructure. With serverless applications, the cloud service provider automatically provisions, scales, and manages the infrastructure required to run the code [1].

Serverless computing is an execution model for the cloud in which a cloud provider dynamically allocates—and then charges the user for—only the compute resources and storage needed to execute a particular piece of code or “pay as you go” [2]. If you do not use serverless, you still must pay for the unused resources.

 

Resources and Demand

Source: Salma REBAI, Allocation et federation des ressources informatiques dans le Cloud (Resource allocation in Cloud federation)

 

What is Function-as-a-Service?

Function-as-a-Service (FaaS) is a serverless way to execute modular pieces of code on the edge. FaaS lets developers write and update a piece of code on the fly, which can then be executed in response to an event, such as a user clicking on an element in a web application. This makes it easy to scale code and is a cost-efficient way to implement microservices [3].

 

Using serverless code like FaaS, web developers can focus on writing application code, while the serverless provider takes care of server allocation and backend services.

 

Should I use serverless?

These are the four main reasons people switch to serverless [4]:

  • it scales with demand automatically
  • it significantly reduces server cost (70-90%), because you don’t pay for idle
  • it eliminates server maintenance
  • it frees up developer resources to take on projects that directly drive business value (versus spending that time on maintenance)

 

Reasons not to use serverless [5]:

  • your workloads are constant
  • you fear vendor lock-In
  • you need advanced monitoring
  • you have long-running functions
  • you use an unsupported language

 

Providers

There are many providers that already support serverless and these are some of them:

  • Lambda (Amazon Web Services)
  • Azure Functions (Microsoft)
  • Google Cloud Functions (Google)
  • IBM Cloud Functions (IBM)

 

Please have a look on the following table to know which one is the most suitable for you [6]:

Features

Amazon Web Services (AWS)

Microsoft

Google

IBM

Serverless Compute Offerings

Lambda
Lambda@Edge

Azure Functions
Azure Event Grid

Google Cloud Functions
Google App Engine

IBM Cloud Functions

Maximum Functions

Lambda – Unlimited
Lambda@Edge –
25 per AWS account

Unlimited

1000 per
project

Unlimited

Scalability & Availability

Transparent –
Automatic Scaling

Automatic
scaling

Automatic

Automatic

Languages supported

§  Lambda – Node.js, Python, Java, C# (.NET)

§  Lambda@Edge – Node.js 6.10

Node.js, C#,
Python, F#, PHP,
Bash, Batch, executable for Azure Functions

Node.js

Binaries in
Docker, Python, Swift, Node.js, Java

Max. execution time

300 seconds
(5 minutes) in Lambda

300 seconds

540 seconds

600 seconds

Max Code Size

50 MB compressed
250 MB uncompressed

None
User pays the storage cost

100 MB
compressed
500 MB uncompressed

48 MB

Monitoring

Dashbird,
CloudWatch

Azure
Application Insights

Stackdriver

IBM Cloud
Shell

Concurrent Executions

1000
concurrent executions per account per region

10 concurrent
executions per function

400 per
function

1000 per
project

Triggers

§  Lambda – S3, Kinesis, DynamoDB, Simple Notification,
Cognito, Simple Email Service, CloudWatch Logs, CloudFormation,
CodeSummit,CloudWatch Events, Echo, Scheduled, Echo, API Gateway, Lex

§  Lambda@Edge – Functions will automatically trigger against
following Amazon CloudFront events – viewer requests, viewer response, origin
request, origin response

Queues,
Schedule, HTTP, Events, Blob Storage

Cloud
Storage, HTTP, Cloud Pub/Sub

Periodic
Triggers, webhook triggers for GitHub, Cloudant noSQL DB, Push Notification
Service, Message Hub Service, Watson, Slack APIs, websocket, weather

Web Editing

Web Editing

Provided

Via Google
Cloud Source

Provided

Logs

Via
CloudWatch Logs

Available

Via CLI and
Stackdriver

Yes

HTTP

Must be
triggered through an API gateway

Directly
triggered via HTTP

Can be
directly triggered via HTTP

Yes

Orchestration

Via the step
functions

Via Logic
Apps

No

Via Rules

Version Control

Versioning
and aliases

Via GitHub
and other similar platforms

Via Google
Cloud Source

No

Deployments

.ZIP to S3 or
Lambda

Via GitHub,
Visual Studio, Local git, Dropbox, Bitbucket

Google Cloud
Source and .ZIP to cloud storage

GitHub,
Bluemix DevOps

Access Management

IAM roles
(identity and access management)

IAM roles

IAM roles

IAM roles

Dependencies

Deployment
packages

NuGet, Npm,
Visual Studio Team Services

Npm
package.json

NA

Limits

§  Lambda – Memory Allocation – 128 MB to 1536 MB

Ephemeral disk capacity –
512 MB

§  Lambda@Edge – Viewer request and response event limits = 128
MB, request timeout = 30 seconds

Azure
Functions under consumption plan, limits the execution time to 5 minutes

Function
calls per second: 1,000,000 per 100 seconds

Memory – min
256 MB and max 512 MB

Timeout – 60000 ms to 600000 ms

Pricing

§  Lambda – 1M requests for free, after that, $0.20/1M
invocations along with $0.00001667/GB-sec

§  Lambda@Edge – Request Pricing is $0.60 per 1 million requests
($0.0000006 per request), Lambda@Edge functions are metered at a granularity
of 50ms

Azure Event
Grid – Price per million operations $0.60

2 million
invocations free. $0.40/million invocations

$0.0000025/GB-sec
with 400,00 GB-sec/month for free

$0.0000100/GHz-sec with 200,000 GHz-sec/month for free

Basic Cloud
Function Rate: $0.000017 per second of execution, per GB of memory allocated

API Gateway: Free/No Limits

REFERENCES:

[1] https://azure.microsoft.com/en-us/overview/serverless-computing/

[2] https://www.infoworld.com/article/3406501/what-is-serverless-serverless-computing-explained.html

[3] https://www.cloudflare.com/learning/serverless/glossary/function-as-a-service-faas/

[4] https://www.serverless.com/blog/when-why-not-use-serverless

[5] https://blog.runscope.com/posts/why-you-might-not-need-serverless

[6] https://www.dailyhostnews.com/serverless-computing-comparison-guide-aws-google-ibm-and-microsoft