What is functions-as-a-service (FaaS)? How does it work? What are some of the benefits and use cases for technology teams?
Web applications consist of code that responds to events such as a user ordering an item, completing a form, or uploading a new image. In monolithic applications, this code is deployed as a single unit that contains all of the logic required to respond to these events. This monolithic approach is no longer able to meet modern requirements. In its place, function-as-a-service (FaaS) offerings are becoming increasingly popular. FaaS allows code to be deployed in a distributed manner, with functions deployed individually based on their scope.
FaaS is a subset of serverless computing. Serverless computing focusses on solutions for software deployment that do not require the preemptive provisioning of physical servers for a piece of software. With serverless, code is run on a server only when required rather than being run continuously in anticipation of requests/events to service.
Deploying a piece of software in a FaaS environment involves breaking down an application into its constituent parts. This is done by determining the different functions that the software encapsulates. These functions can accomplish any task, such as enabling users to upload images, responding to users subscribing to a mailing list, or purchasing an item via mobile applications. They can be deployed individually in a cloud environment, where resources are allocated depending on demand.
FaaS responds to events - which are often user requests - and produces some form of computation, result or other response. The two key components in a FaaS environment are the API gateways and the functions to be executed.
The API gateway is where events get assigned to different functions. The API gateway is responsible for mapping every event to a function and passing the request data to the relevant function. Where required, the gateway will also return the result of the function back to the client. For example, when a user requests information in a mobile application, a call will be sent to the API gateway to retrieve some data from a database. The API gateway will pass on the user request to the correct function, which will execute and return the relevant data from the database. The API gateway will then return this result back to the client. In essence, the API gateway is a middleman between clients and the deployed functions in a FaaS environment.
Sending requests to the API gateway should be the only way that functions are invoked on your service. This provides an easy way to adapt functions that are called based on requests very easily, without ever updating client code. API gateways can also be used to aggregate multiple function invocations together in order to execute a more complex task. A client may send a singular request but more than one function can be executed and a single response returned to the user.
Functions are deployed as stand-alone pieces of code in the FaaS environment within a cloud platform. Each function will fulfill a very specific purpose, such as retrieving a certain type of data from a database, sending a registration email, or processing payment details for a single order. Functions are stateless, which means that they have no concept of past function invocations or any dependencies about the wider application. Once a function is invoked, it produces a result and then it terminates.
While the API gateway orchestrates function triggering after an event, functions can also call other functions. This is sometimes necessary when the input of one function requires the output of another, distinct function. This triggering mechanism allows developers to string together multiple functions and achieve complex use cases efficiently. For example, a user could be registered, a welcome email sent, a coupon code generated and sent via SMS to the user, all from a single event triggering a series of functions.
During idle times, functions are not running at all. In comparison, monolithic applications are always on and waiting to receive requests. Because an always-on infrastructure is wasting resources during idle times, functions only spin up resources when a request is received. The cloud platform where the functions run will allocate resources based on demand, keep them active while the processing takes place, and then spin the resources down. Functions only execute for short times, the maximum time imposed by cloud providers for a function to run being ~15 minutes. This ‘compute on-demand’ approach enabled infrastructure providers to achieve maximum usage and serve more customers, and FaaS users to pay only for what they use.
Serverless computing and more specifically, FaaS provides benefits around scalability, cost-effectiveness, and robustness of an application.
Applications deployed in a FaaS environment are inherently scalable. The number of requests an application will receive is rarely, if ever, static. The number of requests will change based on the time of day, demand for the product and more. Maintaining code that can adapt to this changing load is hard with monolithic applications, as one portion of an application will need to be scaled whilst others will not. FaaS deployments are naturally easy to scale and do not require the extensive management of a traditional auto-scaling service which would be required for a monolith. This allows specific parts of an application to handle more requests than usual, without unnecessarily scaling functions that are not required for the respective event.
FaaS allows applications to integrate with the wider technology ecosystem, especially with a wide array of offerings from Software as a Service (SaaS) providers. Integrating with these solutions has become a common and necessary task in the development of software. Use cases range widely, and can include identity management, engaging social media users, or process payments.
Integration with these services is often quite time-consuming and may require adapting large portions of existing code, if deployed as a monolith. However, FaaS provides the means to deploy a single function to the environment that can be easily created, deployed and run in order to integrate with an external service.
Functions deployed in FaaS environments are only executed when an event is generated. Until then, functions are simply not running, and therefore do not incur costs. On the other hand, monolithic applications need to be run continuously in case a request is received that needs to be serviced. In a cloud environment, hosting a monolithic application in a virtual machine will require the customer to pay for the virtual machine whether the application is used or not. This pay-per-use model will generate bills that are true to the function’s usage.
While this is an inherited advantage of FaaS, cost savings are not guaranteed. Optimal billing can only be achieved when applications are developed efficiently, following a set of best practices, removing any redundant processes and ensuring monitoring and observability over function’s performance.
FaaS can facilitate developers to add new features and integrations to an existing solution in an efficient and non-impactful way. FaaS provides the means for developers to quickly and easily add a new integration or feature based on pre-existing or newly defined events.
With this model, developers can build a new function, test that it performs as intended, and integrate it with the rest of the application just by keeping in mind its triggering, input data and output. In a monolithic environment, new features come with a lot of dependencies, and a buggy new release can disrupt the whole application, rather than just one independent module.
The ease with which developers can deploy new functions to the FaaS environment reduces the time needed to add new functionality to an existing system, freeing time up to invest in optimization, documentation and more importantly, the quicker release of more new features. In addition to ease of deployment, functions deployed to a FaaS environment are decoupled and this leads to smaller business units which are easier to manage. This enforces good development practices and ensures a product is easily maintainable and adaptable by developers in the future.
While FaaS can be used in a variety of scenarios and contexts, some use cases that lend themselves particularly well to serverless computing and FaaS.
Integrating with external services using FaaS is easy, cost-efficient and robust. Becoming a part of the wider technology ecosystem requires integrating third party services in your applications. FaaS facilitates the integration with such services and allows the triggering of the required functions quickly and easily.
Serving static content such as web pages is incredibly simple with FaaS. It is common to serve content such as files and webpages from object storage such as Amazon S3. Given that the content rarely changes programmatically, serving this content is incredibly simple. Simple functions deployed to FaaS environments are a perfect candidate for this use case owing to the inherent simplicity of the serving of this content.
Processing data from data lakes can lead to complex workflows of function calls. FaaS facilitates these workflows by separating the different stages into separate functions that are simple and easy to manage and deploy. Adapting workflows and adding new paths of execution and use cases for the same data is also made far easier due to the easy adaptability of FaaS solutions.
Generating invoices and other static documents is a common functionality. Airlines serve boarding passes in mobile apps, and most e-commerce services have an invoice generation feature. These templates for these documents are ready to be retrieved, populated and served to the user when requested. A simple function can take a small parameter such as a document type, name, user ID and barcode, and produce a document specific to the request.
This use case lends itself well to FaaS as the function is simple, easy to manage and does not require any kind of state. A request for a document is received and the document is returned. Given that this feature could also have variable demand, FaaS also ensures there resources are provisioned when necessary and costs scaled adequately.
Processing of payments is often done using external services via SaaS offerings, often passing data to a payment processor such as Stripe or Paypal. Ensuring payments can be processed almost instantaneously is pivotal in ensuring good user experience and that product orders are well handled. FaaS’s inherent scalability ensures that even during peak times, the number of orders received at any one time will not negatively impact the user experience.
Given that handling payments is often a single step in the wider workflow of ordering a product or buying a service, FaaS is also an excellent method to create the entire workflow, from data gathering, payment processing and invoice creation.
For handling time-based events, FaaS can help businesses who, for example, may wish to send communications every day at a specific time to their customers. Their communications could be an email that contains content based on the current time and state of a product, such as an uptime or usage report. Functions can be triggered based on a time schedule, populate the email with the required information and send it to a distribution list.
FaaS is a subset of serverless computing, whereby applications are run in the cloud without the need to pre-emptively provision cloud resources. Functions are deployed individually and often represent a single business unit of logic which can be strung together for more complex use cases. It is inherently scalable based on demand due to their decoupled nature. FaaS offers a plethora of performance and business benefits, and is particularly useful in a wide array of use-cases, especially when integrating with external offerings presented via the SaaS model.
We're gradually opening up early access to companies who like to build and automate the future of X.