Function-as-a-Service

Demystifying serverless deployments with Zeit Now

Chris Kipp

Hello

Work for Visma connect making qualified information exchange tooling primarily in Scala and JS

Studied international relations, but decided to learn programming and switched careers

Function-as-a-Service

WHAT

WHY

WHEN

WHERE

WHO

DEMO

Jargon

Function

A function is a unit of code that is often defined by its role within a greater code structure. Specifically, a function contains a unit of code that works on various inputs, many of which are variables, and produces concrete results involving changes to variable values or actual operations based on the inputs.

f(x) = x + 2

f(3) = 5

f(4) = 6

Technopedia

Jargon

{ name here }-as-a-Service

PAAS SAAS IPAAS FAAS 

  • A third-party (or internal) provider hosts/provides { name here }  making it available for consumption by consumers
  • For example: Software-as-a-Service

Function-as-a-Service

WHAT

  • Serverless architecture
    • You deploy an individual function or piece of logic and offer that as a service
    • Complete abstraction of servers away from the developer
      • You don't handle the underlying infrastructure
  • Types
    • Req         Res
    • Scheduled tasks/jobs
    • Process Queue

Function-as-a-Service

WHAT

Cloud infrastructure providers typically give us access to several layers of abstraction that map to the traditional counterparts:

Set of computers

Zeit

Cluster

PHYSICAL

VIRTUAL

Computer

VM Instance

Process

Container

Thread

Function

Function-as-a-Service

WHAT

'use strict'

module.exports = (req, res) => {
  if (req.headers.authorization !== process.env.WAKA_FETCH_AUTH) {
    res.writeHead(401, { 'Content-Type': 'text/plain' })
    res.end('Authentication required.')
  } else {
    makeRequest()
      .then(response => {
        console.info(response)
        res.writeHead(300, { 'Content-Type': 'text/plain' })
        res.end(response)
      })
      .catch(err => {
        console.error(err)
        res.writeHead(400, { 'Content-Type': 'text/plain' })
        res.end('Sorry something went wrong with your request.')
      })
  }
}

Function-as-a-Service

WHY

  • Allows developers to solely focus on code, they don't have to worry about the infrastructure
  • You only pay for what you use. You get billed per invocation
  • Easily handle large bursts of usage
  • Makes it simple to create one function per potential entrypoint of your application. If you are familiar with code-splitting, this is like code-splitting for the back end

Function-as-a-Service

WHY

Function-as-a-Service

WHEN

  • In order to scale, it is widely accepted and understood that more copies of your software need to spawn and the incoming load of traffic is balanced between them. This is known as horizontal scalability.
  • Auto-scaling algorithms are based on high-level metrics like CPU or Memory usage. They might scale too eagerly or not quickly enough, therefore not serving some portion of the traffic in an acceptable amount of time

Zeit

LARGE BURSTS

Function-as-a-Service

WHEN

  • The developer might have to spend a lot of time and resources carefully running simulations, setting up metric dashboards, ensuring the algorithms are fine-tuned
  • Typically, when you spawn a server, worker, container, or process, the requests end up all combined into one process, spawned across several cores and computers

  • The developer loses the ability to understand and predict exactly how their software will scale since the metrics as mentioned above are very dynamic

Zeit

LARGE BURSTS

Function-as-a-Service

WHEN

Serverless functions handle an incoming request, run some computation, and responds. If another request comes to the same path, the system will automatically spawn a new isolated function, thus scaling automatically.

Function-as-a-Service

WHEN

At times you may have multiple different parts of your ecosystem that each do independent things and could even potentially be written in different languages, frameworks, etc

┌ thing3.go         Ready               [33s]
└── λ thing3.go (4.69MB) [bru1]
┌ thing2.js         Ready               [17s]
└── λ thing2.js (2.62KB) [bru1]
┌ thing1.js         Ready               [17s]
└── λ thing1.js (2.62KB) [bru1]
┌ thing4.php        Ready               [17s]
└── λ thing4.php (2.42MB) [bru1]
> Success! Deployment ready [41s]

Function-as-a-Service

WHERE/WHO

  • AWS Lambda
  • Azure Functions
  • Google Cloud Functions
  • IBM Functions
  • Whole bunch of smaller companies/providers

Function-as-a-Service

WHY NOT

  • Vendor lock in
  • Giving up full system control
  • Paradigm shift  (Event driven)
  • Latency issues

Function-as-a-Service

Zeit Now

Function-as-a-Service

Zeit Now

  • Deploy in seconds
  • Built in CDN
  • Generous free-tier
  • Automated deployments built into GitHub and GitLab
  • Command line tool is incredible
  • There isn't a huge latency issue
  • Now Dev is a great way to build/test

Function-as-a-Service

Zeit Now

Let's Code an example!

Thanks!

slides.com/ckipp01

wiki.chronica.xyz