Featured image of post An Introduction to Serverless Computing and Function-as-a-Service

An Introduction to Serverless Computing and Function-as-a-Service

What is Serverless Computing?

The term serverless computing can be misleading; how can you compute things without a server? Well, the answer is that you don’t. The term “serverless” comes from the idea that the server is abstracted from the developer, and is totally maintained by the cloud provider. In other words, the developer doesn’t really care what environment their code is run in; they just need it hosted somewhere where it can be executed. This removes the responsibility of infrastructure configuration and maintenance from the developer, but naturally gives them less flexibility and control over the environment.

Types of Serverless Architecture

If you work with the cloud, you are no doubt familiar with the terms IaaS, PaaS, and SaaS. There are, however, a lot more! When we look at types of serverless architecture, the main ones are:

  • Function-as-a-Service (FaaS)
  • Database-as-a-Service (DBaaS)
  • Backend-as-a-Service (BaaS)

In this post we will focus on FaaS, as it’s one of the most versatile types of serverless computing and is the most commonly used. In fact because it’s so widely used, the terms serverless computing and FaaS are often used interchangeably. However we know from the above that this is not entirely accurate.

What is Function-as-a-Service (FaaS)?

FaaS provides a cloud computing service for building and executing functions. The two key properties of FaaS are that it’s:

  1. Serverless;
  2. Stateless.

Serverless

We’ve already touched on the first point; this means that FaaS is designed for use cases where the developer doesn’t care about the environment in which the code is run, or the infrastructure behind it. They only care that it executes and performs it’s function, hence a serverless architecture being the optimum choice for this scenario.

Stateless

With FaaS, functions are executed in stateless containers. A stateless application does not retain any client information on the server from one session to the next. Therefore, FaaS is ideal for executing small, self contained pieces of code which perform a specific function:

Function (noun)
A function is a block of organized, reusable code that is used to perform a single, related action.

Using a stateless architecture has many benefits, but generally speaking a stateless architecture equals less complexity. For more details on this, see this blog post. by Gareth Dwyer.

Vendors

The three main cloud providers all have their own FaaS services:

FaaS Vendors
FaaS offerings from different cloud providers.

They all offer a very similar service. If the developers function is part of a wider solution, deciding which vendor to go with will primarily be based on where the remainder of the architecture is hosted. Other than that, most people will simply choose the cloud provider they’re most comfortable with using.

Where does FaaS sit in relation to more traditional cloud architectures?

The short answer is that it sits somewhere on the scale between PaaS and SaaS.

IaaS vs PaaS vs FaaS vs SaaS
Visual showing where FaaS sits amongst traditional cloud architectures.

The scaling of the containers used with FaaS is entirely taken care of by the cloud provider, and compute power is determined on a per execution basis. When the function is not being executed, there is no compute instance. This ultimately gives more responsibility to the cloud provider compared to when using PaaS, where the developer would be responsible for determining compute requirements and configuring scaling rules.

However, the developer still has full control over the application and function code. This gives more control to the developer compared to when using SaaS, where most application development has been done already and the developer essentially becomes an end user.

What’s the difference between FaaS and Containers?

As mentioned previously, FaaS uses containers to execute functions. Containers themselves are not inherently serverless; using a container service such as Azure Container Instances or Kubernetes means that the developer would still be responsible for configuring and maintaining the containers. FaaS provides a serverless service for the developer by ensuring that the cloud provider takes full responsibility for configuring and maintaining the containers that the functions are executed on.

Benefits of FaaS

We’ve already touched on a couple of benefits, but we’ll set them out in detail here.

  • No infrastructure maintenance
    Due to FaaS being serverless, there is no infrastructure configuration or maintenance required from the developer.

  • Automatic scaling
    Functions are scaled automatically as and when needed, with no input required from the developer. This is a huge benefit over PaaS architecture, where scaling rules have to be set up and maintained by the developer.

  • Often the most cost effective option
    Costing for a function application is done on a per execution basis, meaning you only pay for exactly what compute power your application uses. When nothing is running, there is no cost. For small, isolated, not continuously invoked functions this is usually the most cost effective option. If the function is being executed constantly, this might result in higher costs and a PaaS architecture could be better suited.

Disadvantages of FaaS

  • Cold starts
    After a function has been executed, FaaS keeps the container active (or warm) for a certain period of time. Azure Functions, for example, keeps the container warm for around 20 minutes. However, once the container becomes inactive (or cold), the application becomes subject to cold starts. Usually this has a latency impact of around 1-3 seconds, which for some applications can be critical.

  • Little control over the environment the code is being executed in
    This is the other side of the coin to no infrastructure maintenance. The developer has practically no control over the image used on the container which executes their function. Functions are written in one language, and although the developer can choose the language, this ultimately means a function can only have one runtime stack. Therefore for more complicated applications which may require a more complicated container image, FaaS would not be appropriate. An example of this would be if a Python package was actually a wrapper for a Java library; a Python function would not be able to execute the code because it would not know how to compile Java.

Summary

FaaS is great for executing smalls blocks of code designed to perform a specific action, when the developer is not concerned about the environment the code is being run in. It’s cost effective, and all infrastructure and scaling configuration and maintenance is taken care of by the cloud provider.

However, be mindful that if you require your application to be stateful, use multiple runtime stacks, or have extremely low latency, FaaS may not be the correct solution.

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy