What is function as a service (FaaS)?
Function as a service (FaaS) is a cloud computing model that enables cloud customers to develop applications and deploy functionalities and only be charged when the functionality executes. FaaS is often used to deploy microservices and may also be referred to as serverless computing.
Traditional cloud use requires users to provision cloud infrastructure -- including virtual servers, storage and services -- that hosts application code. That code runs continuously and produces regular recurring business costs.
By comparison, FaaS provides developers with the ability to run one function, piece of logic or part or all of an application and only be charged when the code executes. Code is written into the developer end, and it triggers remote servers to execute the intended action. Unlike other cloud computing models that run on at least one server at all times, FaaS only runs when a function is conducted and then shuts down.
The first FaaS model was released in 2014 by hook.io, an open source platform that hosts webhooks and microservices. Offerings from Amazon Web Services (AWS), Google, IBM, Microsoft and Oracle followed.
FaaS use cases
FaaS offers a convenient and powerful way to build cloud applications that rely on triggered or event-driven behaviors. This approach lets software developers create discrete functions that can be called on demand as needed and that other applications can reuse. Essentially, FaaS enables more modular software designs.
FaaS works in any cloud software project. It has already been adopted in several app development and DevOps areas, including the following:
- responding to any discrete event triggered by software or a real-world event;
- providing application programming interfaces (APIs) for web and mobile applications where developers incorporate FaaS into apps;
- undertaking multimedia and data processing tasks, such as checking input or normalizing a data set; and
- enabling internet of things devices that only communicate when data is available or a real-world event is triggered.
Advantages of FaaS
FaaS is a recent development in most cloud providers' service portfolios. However, vendors have quickly embraced the technology for its flexibility and support for microservices-based software architectures.
FaaS provides the following advantages:
- Savings. FaaS can be cost-effective because developers spend more time writing app-specific code and less time handling the logistics required to manage servers. As a result, less time and money are spent managing infrastructure.
- Efficiency. Development and deployment time is decreased as more workloads are run and costs are reduced.
- Scalability. Applications can be scaled independently rather than integrated within a larger platform.
- Pay-per-use model. Customers are billed based on that amount of executed functionality, meaning money is never spent on inactive resources.
- Feature rich. Features such as support, availability and fault tolerance are inherently included.
Disadvantages of FaaS
FaaS poses several tradeoffs that should be considered before including the functionality in software development projects. The following are some of the potential drawbacks:
- Transparency. There is less transparency into back-end, externally managed infrastructure.
- Security. Users must trust the cloud provider's infrastructure and security.
- Costs. Cost can be hard to predict and incorporate into budgets with the pay-per-use model.
- Testing. Software testing, such as integration and performance testing, can be challenging.
- Vendor lock-in. FaaS features and functionality aren't universal among cloud service providers. Once a customer uses functions from one cloud provider, it can be difficult to change to another provider without careful software updates and testing.
- Integration issues. Because FaaS is relatively new, solutions to issues -- such as keeping track of functions and remote debugging -- have yet to be developed. This makes integration into existing continuous integration/continuous delivery pipelines challenging.
FaaS vs. microservices apps
Modern software design includes various functional or architectural approaches that incorporate FaaS and microservices. However, these technologies are different and serve different use cases.
- FaaS. Function as a service is a form of serverless computing where the cloud provider facilitates the loading and execution of a user's code when triggered by software or hardware events. However, the code serves only a narrow purpose, and such functions are called by and run on a FaaS provider's managed infrastructure.
- Microservices. These are a form of software design where the features and capabilities of software are divided into functional modules deployed independently, either locally or in a cloud. Each module interoperates through APIs. Users typically manage the local or cloud infrastructure used for microservices components.
The common element of both technologies is the use of virtual containers. Microservices components are typically deployed in containers. Similarly, the code that executes when a FaaS job is triggered is loaded and executed in a container.
Microservices and FaaS aren't mutually exclusive; they can be used together in the same software product. For example, software might be architected for the cloud using microservices and also use triggers from microservices code execution -- or a response to events -- to trigger FaaS jobs.
FaaS vs. serverless computing
The terms FaaS and serverless computing are often used interchangeably. Although this is not technically correct, both concepts share the same underlying goal: to eliminate the need for users to configure and manage infrastructure.
A traditional application requires IT to provision and manage the underlying infrastructure -- including servers, storage and networks -- where the application code is deployed. In the broadest sense, serverless computing is any elimination of this infrastructure burden.
For example, when a public cloud provider creates a database service and makes it available to users, the users no longer need to worry about building and managing the underlying infrastructure to operate that resource. The public cloud provider provides and manages the infrastructure, and the user simply invokes the service as needed in the workflow.
FaaS is an extension of the basic concept where the cloud provider handles all of the provisioning and management of the infrastructure needed to invoke and run the user's code. This can be called serverless because users need not concern themselves with the underlying infrastructure.
However, where serverless functions can potentially run continuously, FaaS -- and all event-driven computing -- is typically intended to load and run ephemeral, or short-duration, function execution tasks. If those tasks aren't running at the moment, all of the related infrastructure is freed. Thus, FaaS is typically one expression of the broader serverless architecture idea.
For more on public cloud, read the following articles:
Comparing FaaS vs. PaaS vs. IaaS
IaaS is the traditional representation of cloud computing services. IT resources such as servers, storage and networks are virtualized and made available to users. Users rely on software management tools to select, configure and assemble these resources into a cohesive infrastructure capable of hosting an application for the business.
PaaS is higher level of abstraction where the cloud provider assembles and manages the underlying infrastructure to host and deliver predefined platform services to users. These platforms often include productivity tools -- think Office 365 -- and software development toolchains. However, they are intended for continuous duty and remain available to users 24/7 year-round.
By comparison, a FaaS function is one service in a cloud provider's multiservice portfolio. Functions provide a serverless environment where users don't need to define and configure the underlying infrastructure to execute code. Instead, the cloud provider manages it. This lets users load code, set triggers and execute functions when needed. Once the function code is complete, the underlying infrastructure is released and made available for reuse. All of this happens behind the scenes, hidden from users.
These examples aren't mutually exclusive. Users can engage IaaS, PaaS and FaaS in any combination to facilitate their desired business applications.
Best practices for using FaaS
Although there are few formal limits on FaaS use, there are best practices that help developers get the most from FaaS functions. They include the following:
- Use one event to trigger and run one task only.
- Don't nest functions; one task should not trigger another task.
- Keep functions tight, small and short-lived.
- Keep functions stateless; if a function needs data, let it access data from a source such as storage on each call.
- Minimize dependencies; a function shouldn't depend on many, or even any, outside factors.
- Use security such as permissions and identity and access management features when invoking functions.
- Make functions generic and reusable whenever possible.
All major public cloud providers offer at least one version of event-driven computing services. The following are some of those offerings:
- Alibaba Cloud Function Compute
- AWS Lambda
- Google Cloud Functions
- IBM Cloud Functions based on Apache OpenWhisk
- Microsoft Azure Functions
- Oracle Cloud Functions
When considering FaaS options, it's important for developers to consider the restrictions and limitations of the services. Factors to examine include the amount of code to be executed, the number of calls per second that the cloud can handle and the costs per call.
Take a closer look at AWS Lambda vs. Azure Functions vs. Google Cloud in this comparison of serverless services.