Functions-as-a-Service (FaaS) is a cloud computing model that can be thought of as the plug-and-play of web-based application development. As the ultimate form of serverless computing, FaaS enables developers to deploy production-ready code to the web without having to plan, provision, or maintain any infrastructure or computing resources whatsoever.
It’s not a wholly new cloud paradigm, but adoption of the FaaS model has now matured to a level where it is billed to overthrow PaaS as the new king of serverless computing in 2018 and beyond. In this post, we take a look at how FaaS works, its use cases, and its benefits.
What’s all the FaaS about?
The purpose of FaaS is to help developers take over the world rapidly build, deploy, and extend apps by letting other people (e.g. the Ops folk in DevOps) create and manage the complete server environment on which code can be run. You simply bring the code in the form of individual functions and your FaaS platform does the rest, regardless of whether you’re developing for web, mobile, or IoT.
The elimination of server administration and operations-related duties means no more forgetting where you placed your SSH keys and the simple bliss of doing what you do best – solving problems with code and turning ideas into apps. Hakuna matata, in other words.
Behind the scenes, a FaaS platform typically takes care of the following:
- The networking infrastructure, physical hardware, and storage;
- The allocation and management of resources with virtualization and/or containers;
- The operating system and application runtimes needed to support your code;
- The user interface, CLI, and API for function lifecycle management and organization;
- The compliance and regulatory requirements for data privacy and security;
- The serverless framework or backend engine used to execute functions, optimized for latency;
Then, your FaaS provider hands you the proverbial keys to the kingdom of your own serverless compute cloud, with which you can upload and execute your handcrafted code on demand, instantly.
But that’s not all FaaS is about. In contrast with its sibling model, PaaS, which provides a similar “look ma, no servers” approach, FaaS also offers automatic elastic scaling (fully managed by the provider) and a precise, per-execution pricing structure based strictly on how long your functions take to execute.
How does FaaS work?
While it’s tempting to say, “it just works”, you likely want to know how FaaS works, at least on a basic level. So let’s start by defining what a function is.
What is a function? In computer programming, a function is a single-purpose, reusable piece of code that performs processing of arbitrary data (input), and then returns a result (output). Fortunately, as a fundamental programming concept, functions are functions no matter what language you code in.
Here, FaaS aligns with the concept of Microservices architecture, as each function you deploy becomes its own independent microservice able to be accessed with a basic HTTP request. The result of a function call will typically be returned in JSON format, making it possible to code functions that communicate with other functions which may have been written in another programming language, in true Microservices style. Once your function is live, it can be called from your main application, an event-driven gateway API, or from within other functions that you create.
As a summary, here are the main characteristics of functions in FaaS:
- Short-lived: When a function has finished executing, it doesn’t stick around in memory or elsewhere, freeing up resources for the next function to be called from the cloud.
- Event-driven: Functions don’t start themselves; they need to be called in response to some predefined event or trigger. Alternatively, they can be set up to be called manually (on request).
- Stateless: Functions don’t hold any persistent state and don’t rely on the state of any other currently running processes anywhere in an application.
- Scalable: Each function instance can be replicated instantly as many times as needed to ensure that load requirements are met. Automatic horizontal scaling is a breeze.
- Easily-integrated: Functions can be integrated into any application that can make HTTP requests. Similarly, you can add the functionality of third-party APIs to a function by making REST calls from within that function.
FaaS Use Cases
FaaS can be extremely useful in diverse scenarios ranging from hobbyist-level IoT to enterprise web applications. In theory, the use cases for FaaS are limitless, but there are a number of existing trends in development that lend themselves well to serverless functions. As mentioned, Microservices-based apps are a natural fit to make use of FaaS, since an application can be entirely composed of functions that intercommunicate and exchange information on-the-fly.
Some common use cases are listed below:
- Intelligent handling of events in a real-time data stream or message queue. For example, a large-scale IoT deployment where client-side logic is limited can make use of functions to provide event-based functionality that doesn’t weigh on the devices themselves.
- Routing and in-flight manipulation of messages in a Pub/Sub or similar messaging system. For example, building a complex network of publisher-subscriber relationships becomes easy with functions.
- Extending a monolithic application with separate functions to take care of high volume transactions which can be scaled independently of the monolith.
- Enhancing a simple website or app with dynamic Microservices functionality (e.g. widgets/notifications).
- Handing off compute-intensive tasks (e.g. natural language processing/sentiment analysis/image recognition) to a third-party such as IBM, Altception, or Wolfram Alpha.
- Scheduling once-off tasks for background processing in an automatic, cron-like manner.
- Offloading common or standardized functionality of an app such as authentication to a function, in a Backend-as-a-Service sense.
- Implementing chatbots and adding other AI functionality to an application.
- Applying geolocation and tracking functionality to an application.
- Creating your own ad-hoc webhooks and scripts for any imaginable event.
… And the list could go on. Take a look at PubNub Functions to get a more comprehensive idea of what types of services are available to be run as a function, courtesy of our closest partners. And, of course, where a function doesn’t currently exist to meet your purpose, creating and deploying one is just a few lines of code away.
Benefits of FaaS
Let’s say you have an idea for a healthcare app, but don’t have the expertise or budget to provision your infrastructure in a HIPAA-compliant manner. FaaS presents an excellent solution to this kind of scenario: you simply sign up with a FaaS provider that has the necessary compliance and regulatory framework in place, and use their serverless environment to build your app. It couldn’t get any easier.
That’s one major benefit for the enterprise, but how about for developers more generally? Here are a few of the benefits you can enjoy by going serverless:
- Write code, upload, deploy: This is the basic motto for FaaS because that’s how easy it is to get started. Get your app to market in no time at all by pushing your code to a pre-made platform that’s been tweaked to perfection by a small army of sysadmins, architects, and engineers.
- Extend infinitely, anytime: When an idea for a brilliant new feature hits you in the shower, you can test and deploy it alongside your application immediately, without anything getting in the way of your creative process (or your CI/CD pipeline). Features can be added progressively with no need for lengthy redeployment processes, and the habit of segmenting app components into single pieces of business logic makes it much easier to onboard new developers.
- Save money, save the planet: FaaS can be extremely cost-efficient as you only pay for the time spent on running functions. And, by the nature of serverless, no more idle or over-provisioned servers makes for an energy-wise, Earth-friendly architecture.
- Scale your app to the moon and back: Oh, your app just hit the front page of Reddit? Too bad if you’re not using FaaS, because an influx of a gazillion potential customers just stampeded through and DDoSed your dedicated server, 404’ing every page in sight. Four words say it all with FaaS: automatic, elastic, horizontal scaling.
- High performance, low latency: When your FaaS provider’s livelihood depends on maintaining infrastructure that is highly optimized for performance and low latency, you can be sure they’re going to get it right. Let a professional operations team sweat over the finer details of running a streamlined compute platform, and sleep easy with a 99.999% SLA powering your functions.