§15.3.

Serverless

In serverless computing, short functions are deployed to a cloud service provider and executed on demand.

Serverless does not mean there is no physical server. Instead, the cloud provider is responsible for managing the servers required to run the functions.

Serverless is an important technology because it embodies the cloud computing mindset of not owning servers, perhaps more than any other cloud provider offering.

How serverless works

To use serverless, you first write a function in your preferred programming language (AWS supports Node.js, Python, Ruby, Java, Go or .NET Core).

You deploy this code to the cloud provider using a public API or the cloud’s command-line tools. Alternatively, you might copy-and-paste the code into the cloud provider’s management console.

The cloud providers has many servers, booted up, and waiting to handle incoming requests. When an incoming request arrives (this could be a HTTP request or an internal event generated by another service), then a server will download your deployed code and execute the function.

That same server will keep your deployed code in memory for several minutes or up to an hour, to handle any additional requests without needing to reload your code.

If there is a sudden surge of requests, then the cloud provider will load the code onto additional servers. Serverless can scale your code from one user to potentially millions of requests handled by thousands of servers nearly instantly.

Reflection: Principles for serverless code

Serverless code is loaded on-demand (i.e., when the user makes a request). This loading process takes time, which adds latency to request handling.

Based on this (short) explanation of serverless, what principles should apply when writing serverless code?

Serverless offerings

All of the major cloud providers have a serverless offering:

Pricing should be a careful consideration with serverless. Serverless is ideal for websites with low usage but occasional bursts of high-demand. However, the cost per second is quite high. Predictable workloads with constant high-demand may be more affordable in traditional server configurations.

Exercise: Serverless Hello, World!

Create a simple “Hello, world!” style web-page using the serverless feature of your preferred cloud platform.