The Complete Guide to Serverless Apps I - Introduction
Tags: cloud, serverless, webassembly, cloudnative
Published: 2024-06-26 15:00:00

'Serverless' as a term [first appeared](https://martinfowler.com/articles/serverless.html#origin) around 2012 but it was only in 2014 when it piqued interest after the launch of AWS Lambda. The term spiked in usage in 2020 but went into decline soon after. Early in 2022, interest began to climb again. And right now, the term is as popular as it's ever been. 

![serverless google trends](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v77c9civgs2ouk5py94s.png) 

There are few reasons for this increase in popularity (which we will delve into shortly) but I thought I'd take this opportunity to draw on my experience working in the cloud, and write a primer for Serverless Applications. This is intended to be read like an e-book and will cover all the facets of Serverless applications.  

Here's the Complete Developer’s Guide to Serverless Apps which will be serialized over the course of the next few weeks.

### Table of Contents

{%- # TOC start (generated with https://github.com/derlin/bitdowntoc) -%}

- [Defining Serverless 💫](#defining-serverless)
      + [Definition 1: Serverless as SaaS](#definition-1-serverless-as-saas)
      + [Definition 2: Serverless as Hosted Application](#definition-2-serverless-as-hosted-application)
      + [Definition 3: Serverless as a Software Concept](#definition-3-serverless-as-a-software-concept)
- [What is a Serverless App 🤓](#what-is-a-serverless-app)
- [Comparing Serverless Apps and PaaS 🗒️](#comparing-serverless-apps-and-paas)
- [Conclusion 😊](#conclusion)

{%- # TOC end -%}

## Defining Serverless 💫

A friend of mine once argued that there is no such thing as _serverless_ because, of _course_ there are servers underneath every one of the services mentioned above. 

<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExOWVlcnl6MTV2OTdkM3hsNDZmNGxzNDR4dnVjYWhiaTh5cHl2NzlvMSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/eUrE2DuMKOE0g/giphy.gif">

While he is not wrong in his statement that the things described as _serverless_ do indeed have servers running somewhere, he missed the main point: _Serverless_ is a statement about what resources you must be concerned with and not so much about the actual presence of physical server hardware. 

Let’s dive into three definitions of Serverless, and you’ll soon see what I mean. We’ll start with the most generic definition and work toward the most specific.

#### Definition 1: Serverless as SaaS

The most generic term “serverless” indicates that some offering is run using the Software-as-a-Service (SaaS) model. In SaaS, an entire application is owned, built, and operated by one organization, and other individuals or organizations create accounts to use that application, typically via the web.

Some SaaS providers prefer to use the term “serverless” to describe the SaaS model, particularly when they want to emphasize that you, as the user, don’t have to do any management of the cloud resources required to run the SaaS.

If this is server-_less_, then what does “server” mean here? The _server_, that this _serverless_ offering is hiding from you is what used to be called the _application server_ (back in the pre-cloud days). In other words, the machine or machines whose job it was to execute a specific piece of software.

<figure>
<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExYjh1d3ZsZHRueTBoZjZha3dqN2d0ZDh0a24ydmV4dzN6N2E4ZGVsdyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/3o7524uhfdq7pmiDJe/giphy.gif">
 <figcaption>Err..not that Sass</figcaption>
</figure>

> Definition 1: _”Serverless” merely means no management of cloud resources_

You can spot this usage of the term easily. For example, when _serverless_ is being used as a synonym for _SaaS_ it signals that:

* the offering is targeted toward non-engineers,
* there is no REST API, library, SDK, or CLI to use, and
* the web interface is the only way to interact with the application.

#### Definition 2: Serverless as Hosted Application

Consider the following cloud services, each of which claims to be serverless:

* Serverless database hosting.
* Serverless logging and monitoring.
* Serverless messaging framework.

What do these three have in common? A serverless database is one in which someone else manages the database software (starting and stopping, upgrading, patching security issues) and you simply use the database (creating tables, running queries, inserting data).  Similarly, “serverless logging and monitoring” suggests the same: Someone else manages a bunch of servers that do log processing and monitoring, and you merely use the APIs provided to attach to your application.

<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExbmg3bmw1dHhqdDl4Zjl0amNwem53ZTY4Zm5zMnlxZnh5MXE0c251ZCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/nH6AAUMOMxYhvzcmZU/giphy.gif">

This definition treats the word “server” as referring to the hardware or Virtual Machine (VM) instance. While you (the user) may be required to say what kind of Operating System (OS) or architecture you prefer their cloud service to run on. In this case, you perhaps also choose your memory and/or storage requirements but you are not responsible for the day-to-day operations relating to any of this infrastructure.

> Definition 2: _”Serverless” means you (the user) do not have to manage the infrastructure that your cloud services runs on._

You can spot the meaning of “serverless” in this context when the offering:

* is engineering-oriented,
* has a REST API, libraries, SDKs, or CLI client,
* allows you to create instances of this offering for your usage (but you don’t have to manage the day-to-day operations like upgrading, patching, or monitoring), and
* typically does not allow you to gain access directly to the operating system (such as a shell prompt or system administrator account).

#### Definition 3: Serverless as a Software Concept

Consider the process of building a Ruby on Rails, Python Django, or Node.js Express application. One of the first things you must do is write the code that starts a server to listen on a particular port. Or, if you go a level lower than these common frameworks, you might even have to create a socket server, attach a thread pool, and map incoming requests to an HTTP (or other protocol) handler. When you are doing any of these things, you are writing a _software_ server.

In the software world, a server is a long-running process that listens for incoming requests (usually on a network connection) and then handles those requests. A server typically handles hundreds to millions of individual requests over its lifetime, which may span hours, days, months, or even years before the server is restarted.

Contrast this with a program where, instead of standing up an entire server, you merely write a function that starts up (receives a single request), handles that request, and then optionally returns a response before it shuts down. That is, each request executes the program from start to finish. Such a program may run for milliseconds, seconds, or perhaps several minutes. But rarely does it run longer.

<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExNnQxM3dpeGg4NngxaWo3dDB0NmQzZW85NW8xc3ZxaDFubnc3NGk4dyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/nn0Kcrd72zzaZb1WxW/giphy.gif">

This is the serverless app model. And this is our third usage of the term “serverless”.

This model gained the name “serverless function” when Amazon released its Lambda offering.

> Definition 3: _“Serverless” means you do not have to write the software server that will listen for requests, nor do you need to manage the hardware or operating system_

You can spot the meaning of the term “serverless” in this context when:

* you, the developer, write request (event) handlers instead of software servers,
* a variety of SDKs, APIs, or tooling are provided to make it easier for you to write programs,
* you do not need to manage server hardware or virtual machines, and
* you also typically do not have administrator access or shell access to the environment executing your code

## What is a Serverless App 🤓

A serverless app is a thing that runs inside of an environment that manages all of the protocol-level and process-level aspects of serving content. Additionally, that serverless environment provides a layer of secure isolation from other serverless apps. In the strongest cases, this allows multitenant hosting, where two different customers or users can run their apps on the same serverless app platform without fear that the other users or customers can tamper with the app.

A serverless app is the piece of software you, as the developer, write and upload to a serverless application platform. And the code you write is started when a new request is received. Your code is expected to handle that request and perhaps return a response, at which point your code is shut down again (ready to be started again in the future).

>For the most part, it is acceptable to use the terms “serverless app” and “serverless function” interchangeably. In this guide, we tend to use _serverless app_ because it is more generic (and also shorter to type). Where it is necessary to distinguish between the two, we do so carefully.

## Comparing Serverless Apps and PaaS 🗒️

It is useful to contrast a serverless app with an app written for a Platform-as-a-Service (PaaS). Heroku and the open-source [Cloud Foundry](https://www.cloudfoundry.org/) are examples of PaaS. In contrast, [Fermyon Cloud](https://fermyon.com/cloud) is an example of a serverless app platform, and [Spin](https://fermyon.com/spin) is a developer tool for building serverless apps.

For starters, Serverless apps are more cost-effective than long-running servers in a PaaS environment.  A serverless app is simpler, faster, and more resource-efficient than a PaaS. But let's dive into the conceptual details to see why this is the case.

In a PaaS, you (the developer) write an application in any language the PaaS supports. And then you deploy that application to the PaaS service, where it is hosted on your behalf. Developer self-service is a core feature of a PaaS. That means developers can deploy their applications without relying upon an operations (DevOps or platform engineering) team.

Most serverless app platforms, including [Fermyon Cloud](https://fermyon.com/cloud), also provide the same kind of developer self-service, including a web dashboard, metrics and monitoring, and a host of tools to assist in developing and debugging.

Where a PaaS differs from serverless apps is, again, in the programming model. A PaaS follows [definition 2 of serverless](#definition-2-serverless-as-hosted-application) where the hardware is managed, but the developer must still write a _software server_.

Meanwhile, serverless apps follow [the 3rd definition of serverless](#definition-3-serverless-as-a-software-concept). Whereby a developer writes only the small program that handles a request and does not have to worry about writing the software server.

If you are looking for a developer self-service platform to run long-running services that are always on, a PaaS is probably the solution you are after. If you are looking for a developer self-service platform where you can quickly write highly efficient apps that need to execute instantly and scale rapidly, you may prefer to take a look at serverless apps. 

## Conclusion 😊

That was a comprehensive look at defining Serverless and Serverless apps. In the rest of the series we will look at the characteristics of a serveless function, the use cases and of course some code. 

<img width="100%" style="width:100%" src="https://i.giphy.com/media/v1.Y2lkPTc5MGI3NjExazlsa212MWZvamt6Y2dwdHQzeXZscjk3bjc0MTVkbjQ3MmZvanJubCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/DAzIIpUmSgFXbp1hFV/giphy.gif">

Let us know in the comments if you are using Serverless already, and what your usecases are!