Technologies such as virtualization and containers have greatly changed the methods used to deploy software. When combined with DevOps practices, these technologies increasingly empower developers to build sophisticated systems without the need to worry about the provision of computing resources. This model is called cloud computing.
The evolution of "the cloud" has been towards greater abstraction. The job of systems administration is increasingly outsourced to a cloud provider, and the software developer is freed to focus exclusively on the application or program logic. Or at least, this is the sales pitch. The logical endpoint of this model is towards a fully abstracted system, where it is possible to run program logic without worrying about the systems on which it executes or how it is provisioned.
Many cloud providers are now beginning to offer services that allow exactly this type of model. Commonly called "serverless" or "Functions as a Service (FaaS)," such systems provide many important benefits. These include:
- Complete Platform Abstraction: The "cloud" manages all infrastructure, components, and deployment.
- Highly Scalable Performance: The most common platforms scale the application in response to program events and provide sufficient resources for required actions without requiring a developer or administrator to plan for the load.
- Pay As You Go: Because of the way in which the application executes and scales, most services allow for sub-second billing. AWS Lambda, one of the most popular platforms, tracks consumption multiple times per second. Since most computing resources are frequently idle, even in cloud environments, it is possible to have enormous savings after migrating to serverless platforms. Some companies, such as Financial Engines, have reported cost savings of more than 90% by adopting serverless platforms in their infrastructure.
In this article, we will take a closer look at serverless computing. We'll dig further into how it works, the types of workloads and use-cases it works well for, available platforms (with a special emphasis on those which are open source), and a few of its limitations.
Upon beginning any discussion about Serverless computing, you quickly arrive at an important point: Serverless actually covers a range of techniques and technologies. Two of the most common include:
- Backend as a Service (BaaS). Backend as a service are software components that are fully managed by a provider and can be integrated into an application. These include things that manage data, such as Google's Firebase, a popular database that is used by developers writing single-page applications or mobile apps, or security.
- Functions as a Service (Faas) or Serverless Compute. FaaS (as noted earlier) is a generic environment in which minimally packaged applications can be run without worrying about the provision and deployment of resources. FaaS environments expose an application programming interface (API) which allows developers to create functions that can respond to events. The cloud environment then handles the provision of function instances in response to those events. When the function has completed its execution, the cloud will tear it down.
Of the two techniques, FaaS has received most of the attention and is, in fact, where a lot of the buzz about Serverless comes from. While many discussions treat FaaS and Serverless as synonymous (and this article will focus mostly on Faas), that is only part of the picture.
FaaS has become extremely popular amongst developers because it utilizes event-driven architectures with which they are already comfortable and minimizes deployment headaches such as implementing, configuring, or scaling a server. An additional benefit is that Serverless architectures can be configured to automatically scale with an application's needs. During periods of high demand, the system can burst to cover the capacity required and then idle back to effectively zero.
Because FaaS is inherently event-driven, there is often more to a platform than an environment to host and execute code. Alongside this, there will be a set of sources to execute synchronous and asynchronous events. An example of synchronous events might include an HTTP API Gateway while asynchronous sources might include a message bus (such as Apache Kafka), an object storage (such as Amazon S3 or Minio), or a scheduled event similar to cron. As of this writing, Amazon Lambda incorporates more than twenty types of event sources.
Data Processing with Serverless
Because of its event driven nature and strong integration with message hubs and web API gateways, serverless has become popular for code that needs to respond to changes in upstream state. These include workflows that might be triggered by a signal, a file-upload, or a server request. This makes it especially well attuned for building data processing systems and pipelines.
In a 2017 report, the research firm Gartner identified more than fifty solutions within the FaaS ecosystem, underscoring the tremendous interest in Serverless technology. While the vast majority are open source and extensions of existing businesses, like Platform9's Fission, there are also many stand-alone implementations that take advantage of technologies such as containers and Kubernetes. In this section, we look at some of the most popular platforms.
AWS Lambda is Amazon's serverless web service that offers multi-language support including Node.js, Java, C#, and Python. Lambda comes as part of a large application ecosystem including systems like Dashbird and Cloudwatch which provide real-time monitoring for the associated infrastructure.
Google Cloud Functions
Google Cloud Functions is Google's approach to provide a FaaS platform for users. Google Cloud Functions is one of the newest additions to the cloud landscape and supports functions written in Node.js, Python, and Go. Like Lambda, Google Cloud Functions exists as part of a large ecosystem and includes tools such as Stackdriver (Google's monitoring system).
Microsoft Azure Functions
Microsoft Azure Functions is Microsoft's serverless computing platform. It supports common .NET languages like Node.js, C#, F# in addition to open languages such as Python, PHP, and Java. In addition to the established languages supported by Azure, it also provides support for specialized languages, such as a system that allows for the execution of batch files. Azure Application Insights is the built-in monitoring system.
IBM Cloud Functions
IBM Cloud Functions is a FaaS programming platform that is based on Apache OpenWhisk. It supports languages like Node.js, Swift, Java, PHP, Go, and Python. Additional languages can also be integrated through the use of containers. The monitoring and user interface for OpenWhish is provided by Cognos Dashboard.
Benefits and Tradeoffs
OpenFaas is an open-source FaaS platform built on top of containers. Built with the goal of simplifying the deployment of event-driven functions and microservices on top of Docker and Kubernetes, the framework provides a software stack to build robust serverless systems. Like Kubernetes, OpenFaas is free and not tied to any specific cloud provider. This means that it can be deployed into a number of cloud environments and allows for a self-hosted FaaS solution.
OpenFaaS Cloud Native Stack
OpenFaaS utilizes Kubernetes and Docker for its runtime. Tooling which reads YAML files are used to package and deploy function templates. Supporting components include:
- Docker: containerizes the application functions and provides the mechanism by which they are deployed.
- API Gateway: provides an entry point to functions.
- Function Watchdog: embedded in any container, provides the runtime element that allows container based functions to start.
- Prometheus: provides monitoring capabilities to collects statistics of the system. System wide stats are collected by communicating with supporting infrastructures such as Docker Swarm or the Kubernetes API.
FaaS for Containers
Through the use of Docker, OpenFaas allows your functions to be built with any programming language. Machine learning, batch jobs, image/video conversion/IoT, and chatbots are all serverless use cases. Anything can run as a serverless function as long as it can be containerized. For this reason, OpenFaas often bills itself as a "Containers as functions" platform.
- Simple user-interface display portal
- Write functions in any language that can be packaged in Docker image format
- Portable in order to run onsite hardware or public/private cloud servers (Kubernetes and Docker Swarm native)
- Command-line interface (CLI) and YAML format for templates and defining functions
- Auto-scaling of resources as demand increases/decreases
Serverless is the next evolution of cloud computing. It provides a pattern for packaging logic while completely abstracting away the underlying environment and administration. This provides beneficial features including on-demand resource scaling and automated infrastructure management, improved efficiency, and pay as you go pricing.
Many providers offer great platforms to host functions in a cloud environment. Open-FaaS provides a free solution for teams who want to develop functions that are able to run in Kubernetes, enabling cross-cloud or self-hosted deployments.
While powerful with many practical benefits, Serverless really shines in data processing workflows such as real-time event processing, ETL, and web/mobile app backends.