What is FaaS in Cloud Computing?
"Cloud computing's evolution introduces Function as a Service (FaaS), a model where developers focus solely on coding without managing the underlying infrastructure. FaaS, part of the serverless computing paradigm, distinguishes itself by reacting to event-driven triggers and automatically scaling resources based on demand. As a subset of Serverless, FaaS is vital for deploying microservices, allowing functions to perform specific tasks within an application.
The FaaS market is rapidly expanding, expected to grow from 3.01 billion dollars in 2018 to 24 billion dollars by 2026. This growth signifies FaaS's impact in cloud computing, offering fault tolerance, scalability, and availability. This article delves into FaaS, highlighting its role in cloud service models like IaaS, PaaS, and SaaS and its significance in the current cloud computing landscape."
Some Popular Examples of FaaS Platforms Include
- IBM Cloud Functions
- Amazon's AWS Lambda
- Google Cloud Functions
- Microsoft Azure Functions (Open Source)
- OpenFaaS (Open Source)
FaaS and Serverless
Before getting into FaaS, let's answer a few questions, what is serverless computing? Does serverless mean no server is involved? The answer to this question is; there is no computing model without servers. Here, by serverless, we mean the management of the servers and other infrastructure and development platforms will be handled by the cloud service provider. The developer only has to focus on writing code and developing business logic.
Serverless is focused on any service, be it computing, database, storage, API gateway, etc., where configuration, messaging, and billing of servers are hidden from the end user. While FaaS is a way to implement serverless computing, which is focused on the event-driven computing paradigm wherein the functions only run in response to events or requests. The event can be any action like pressing any key or clicking any button, etc., which can invoke the function.
In other models, at least one server is continuously running to provide services, even when it is idle. This incurred additional costs for the users. FaaS provides the ability to run only one function, a piece of logic, or part or all of an application and only be charged when the code executes. Faas only runs when a function gets invoked and triggers the remote servers to execute the intended action and then shuts down. In this manner, no cost is paid when the server sits idle.
After understanding the basics of FaaS and Serverless computing. The question arises, how does Faas work?
How does Function-as-a-Service Work?
In the early development era, applications were developed following monolithic architecture. This means the application was developed as a single execution and had to be triggered all at once. This architecture incurred high costs and more development time. Over time, developers have shifted to using microservices. In a microservice architecture, an application is broken down into independently deployable functions. A function is a piece of software that can run one business logic on an operating system in response to an event. An application can be composed of many functions.
In FaaS, the service provider will start the server when the function is triggered by any event. It will execute the function to accomplish the intended task and then shut down the server. Once the server is shut down, the same computing resources can be allocated elsewhere.
The developers using FaaS have access to the development platform that allows them to execute the code for their applications. For maximum efficiency of FaaS, each function should only perform a single action. Based on the need of the server and workload, the system automatically gets scaled up and down in the runtime. This is an important feature of Function-as-a-Service in cloud computing.
Dynamic Scaling with FaaS
A service provider makes a function available through an Application Programming Interface(API) and manages the resource allocation on its own. Since FaaS is event-driven and not resource-driven, the functions are easily scalable which increases efficiency and value.
A function execution time should be less so that it can quickly start up and run. A function starts within milliseconds and processes individual requests. A function is stateless and follows shared-nothing architecture. This means that each running function is isolated and will handle one and only one request at a time. If there are multiple simultaneous requests for a function, the system will create as many copies of the function as needed to meet the demand. When demand drops, the system automatically scales down. This is the dynamic nature of FaaS.
Dynamic Scaling is cost-efficient as users only have to pay for the resources utilized and not for the idle time.
Benefits of FaaS
Function-as-a-Service model is widely used in a development environment that requires a high level of agility. Similarly, the following benefits of FaaS make it shine in rapid application development.
- The ability to focus solely on coding and development of the application.
- Increased developer productivity and faster development time.
- Easy to scale and horizontal scaling is managed by the platform.
- Cost-efficient, since you pay only for what you use.
- Faster time to market due to ease of development and testing.
- Platforms are polyglot, meaning functions can be written in any language.
Principles and Best Practices
Function-as-a-service is prominent because of its simplicity in development and the scalability of the system. Some practices can be followed to make FaaS easier to deploy and more effective.
- Each function should perform only one action - FaaS function is a single unit of code, designed to achieve a specific functionality or business logic. Therefore, a function should only be programmed to accomplish a single task. The scope of the function code should be limited, efficient, and lightweight so the function can load and execute quickly.
- Do not call other functions from one function - The isolation of functions is necessary for FaaS. More function calls from a single function will increase the execution time and therefore the cost.
- Use as few libraries as possible - Using too many libraries in function will slow down the execution time and will make scaling of application a difficult task.
Following these practices will make the FaaS application more efficient in terms of complexity, deployment, cost, and scalability.
How do FaaS and Serverless Differ?
When we talk about FaaS and Serverless computing, there is a very thin line differentiating both these. Serverless computing is a method of providing backend services on an as-need basis. Serverless covers a wide range of categories such as computing, storage, serverless databases, DevOps pipelines, Kubernetes, etc. In serverless, the management of the servers and underlying infrastructure is hidden from the end user and is managed by the cloud service provider. Function-as-a-Service is a subset of serverless that focuses on the computing paradigm. In FaaS, the user is provided with the platform to write the code and build the business logic without worrying about other infrastructural management. The code is executed in the stateless compute instances(containers) that are managed by the cloud provider. FaaS follows an event-driven approach for invoking functions to accomplish the specified task.
Unlike FaaS, Serverless offers many more options and is not limited to creating functions. It is best suited if the main goal is to reduce the infrastructure management responsibilities while retaining control of the application configurations.
Use Cases of FaaS
Funciton-as-a-Service is a rapidly growing service model because of its simplicity, cost-efficiency, fault tolerance, availability, and high scalability. FaaS can be used in a variety of ways; some of the most popular use cases of FaaS are:
- APIs for mobile and web applications
- FaaS is a great option for event-driven applications like RESTful. Sites that load dynamic content use functions to call an API and then populate the appropriate information. Moreover, websites that require user input, use functions to call API for verification of input data.
- Serverless APIs are easy to build and maintain and get scaled up or down on-demand basis. This saves a lot of costs for organizations during peak times and heavy traffic.
- Multimedia and Data Processing
- Faas is frequently used to process the input data, such as multimedia. One common use case is using FaaS to trigger a response based on the type of multimedia input.
- FaaS is very efficient in handling large amounts of input data for the processing which allows developers to make robust data pipelines with little or no maintenance of infrastructure. FaaS allows developers to write single function for different processing components which save a lot of development time and ultimately cost.
- Internet of Things
- Internet of Things(IoT) refers to devices that use the internet to perform functions. IoT has seen immense growth and these devices can easily be found in our homes. These devices are increasingly using FaaS to execute their task by sending and receiving data when triggered by an event. Since they are not using any computing power, the user does not need to pay for the same. At the same time, due to auto-scaling, the developer need not to worry about the unpredictable usage pattern of the devices.
FaaS vs PaaS, Containers and VMs
Function-as-a-Service, Platform-as-a-Service, Containers, and Virtual Machines all play a significant role in serverless computing. But, FaaS is the most central element of the Serverless stack. Let's understand how FaaS differs from other models.
- Provisioning Time - Milliseconds for FaaS and minutes to hour for other models.
- Administration - No administration is required for Faas while it is easy to hard for PaaS, containers, and VMs respectively.
- Scalability - Each action is instantly scaled based on the functional needs while other model offers automatic but slow scaling that requires careful tuning of auto-scaling tools.
- Availability - FaaS is highly available with no extra cost or effort. Other models require additional cost and management for high availability.
- Capacity Planning - No planning is required due to dynamic scaling while other models require the provision of some auto-scaling and capacity planning.
- Persistent Connection and State - FaaS functions run in stateless containers which means they have limited ability to persist connections and the state must be stored in an external resource. On the other hand, the other models can leverage http methods to keep an open socket or connection for long durations and can store the state in memory between calls.
- Resource Utilization - Maximum resource utilization in FaaS due to event-driven architecture, the resources are allocated only when the function is triggered by an event. All other models require at least one server to continuously run to provide service, even when it is idle.
- Resource Limits - Only FaaS model set boundaries on code size, memory, execution time, etc.
- Maintenance - In FaaS and PaaS, the underlying infrastructure is maintained by the Cloud Service Provider. Containers and Virtual Machines require significant maintenance which includes updating the operating systems, connections, container images, etc.
These all are the factors that make Function-as-a-Service an evident choice of developers and organizations for rapid and agile development of applications.
- Function as a Service allows developers to focus solely on writing code and business logic.
- FaaS is a subset of serverless computing.
- FaaS provides a platform to build, compute, run, deploy, and test functions of the application.
- FaaS is based on an event-driven paradigm i.e. a function is invoked by an event.
- The resources are allocated to the function only when it is invoked by an event, that is, there is no idle time.
- A user only pays for the time the function is getting executed. Hence, FaaS is cost-efficient.
- High Availability and fault tolerance are inherently equipped with FaaS in cloud computing.
- FaaS provided dynamic or elastic scaling feature means a function is instantly scaled up or down based on the need.
- Serverless apart from computing focuses on multiple domains such as storage, database, Kubernetes, data pipelines, etc.
- FaaS reduces development time by increasing developer productivity.
- The developer can write the code in any language since FaaS platforms are polyglot.
- Function is an independent entity, therefore each function should perform only one task.
- FaaS is widely used in APIs for mobile and web applications, IoT devices, and multimedia and data processing.
- IBM Cloud Functions, Amazon's AWS Lambda, Google Cloud Functions, Microsoft Azure Functions, and OpenFaaS are popular examples of Function-as-a-Service Platforms.