An introduction to FaaS—a cloud computing service that makes it easier for cloud application developers to run and manage microservices applications.
What is FaaS (Function-as-a-Service)?
FaaS (Function-as-a-Service) is a type of cloud-computing service that allows you to execute code in response to events without the complex infrastructure typically associated with building and launching microservices applications.
Hosting a software application on the internet typically requires provisioning and managing a virtual or physical server and managing an operating system and web server hosting processes. With FaaS, the physical hardware, virtual machine operating system, and web server software management are all handled automatically by your cloud service provider. This allows you to focus solely on individual functions in your application code.
FaaS vs Serverless
Serverless and Functions-as-a-Service (FaaS) are often conflated with one another but the truth is that FaaS is actually a subset of serverless. Serverless is focused on any service category, be it compute, storage, database, messaging, api gateways, etc. where configuration, management, and billing of servers are invisible to the end user. FaaS, on the other hand, while perhaps the most central technology in serverless architectures, is focused on the event-driven computing paradigm wherein application code, or containers, only run in response to events or requests.
Benefits of FaaS
FaaS is a valuable tool if you’re looking to efficiently and cost-effectively migrate applications to the cloud. The following are some benefits you will enjoy:
- Focus more on code, not infrastructure: With FaaS, you can divide the server into functions that can be scaled automatically and independently so you don’t have to manage infrastructure. This allows you to focus on the app code and can dramatically reduce time-to-market.
- Pay only for the resources you use, when you use them: With FaaS, you pay only when an action occurs. When the action is done, everything stops—no code runs, no server idles, no costs are incurred. FaaS is, therefore, cost-effective, especially for dynamic workloads or scheduled tasks. FaaS also offers a superior total-cost-of-ownership for high-load scenarios.
- Scale up or down automatically: With FaaS, functions are scaled automatically, independently, and instantaneously, as needed. When demand drops, FaaS automatically scales back down.
- Get all the benefits of robust cloud infrastructure: FaaS offers inherent high availability because it is spread across multiple availability zones per geographic region and can be deployed across any number of regions without incremental costs.
Principles and best practices
There are several best practices you can follow to make using FaaS easier to deploy and more effective:
- Make each function perform only one action: FaaS functions should be designed to do a single piece of work in response to an event. Make your code scope limited, efficient, and lightweight so functions load and execute quickly.
- Don’t make functions call other functions: The value of FaaS is in the isolation of functions. Too many functions will increase your costs and remove the value of the isolation of your functions.
- Use as few libraries in your functions as possible: Using too many libraries can slow functions down and make them harder to scale.
Because it enables transactions to be isolated and scaled easily, FaaS is good for high-volume and embarrassingly parallel workloads. It can also be used to create backend systems or for activities such as data processing, format conversion, encoding, or data aggregation.
FaaS is also a good tool for Web apps, backends, data/stream processing, or to create online chatbots or back ends for IoT devices. FaaS can help you manage and use third-party services. If you’re considering Android app development, for example, you can adopt a FaaS approach to keep your costs in check. Because you’re only charged when your app connects to the cloud for a specific function like batch processing, costs can be considerably lower than they would using a traditional approach.
FaaS can also dramatically boost computing performance. For example, two students recently worked with IBM engineers to explore how to leverage IBM Cloud Functions for Monte Carlo simulations (mathematical methods used to estimate the future outcomes of certain hard-to-predict events) to estimate stock prices. Monte Carlo simulations are considered an important high-performance computing workload. The combination of Monte Carlo and IBM Cloud Functions enabled the team to run computations on a massive scale and allowed them to focus on the business logic. Using FaaS, the team completed an entire Monte Carlo simulation in about 90 seconds with 1,000 concurrent invocations. Comparatively, running the same flow over a laptop with four CPU cores took 247 minutes and almost 100% CPU utilization.
To see more examples of FaaS use cases, check out “A Recap of the Key Advantages Offered by IBM Cloud Functions.”
FaaS vs. PaaS, containers, and VMs
FaaS, PaaS (Platform-as-a-Service), containers, and virtual machines (VMs) all play a critical role in the serverless ecosystem. Because FaaS is the most central and most definitional element of the serverless stack, it’s worth exploring how FaaS differs from other common models of compute on the market today across key attributes:
- Provisioning time: Milliseconds, compared to minutes and hours for the other models.
- Ongoing administration: None, compared to a sliding scale from easy to hard for PaaS, containers, and VMs respectively.
- Elastic scaling: Each action is always instantly and inherently scaled, compared to the other models which offer automatic—but slow—scaling that requires careful tuning of auto-scaling rules.
- Capacity planning: None required, compared to the other models requiring a mix of some automatic scaling and some capacity planning.
- Persistent connections and state: Limited ability to persist connections and state must be kept in external service/resource. The other models can leverage http, keep an open socket or connection for long periods of time, and can store state in memory between calls.
- Maintenance: All maintenance is managed by the FaaS provider. This is also true for PaaS; containers and VMs require significant maintenance that includes updating/managing operating systems, container images, connections, etc.
- High availability (HA) and disaster recovery (DR): Again, HA is inherent in the FaaS model with no extra effort or cost. The other models require additional cost and management effort. In the case of both VMs and containers, infrastructure can be restarted automatically.
- Resource utilization: Resources are never idle—they are invoked only upon request. All other models feature at least some degree of idle capacity.
- Resource limits: FaaS is the only model that has resource limits on code size, concurrent activations, memory, run length, etc.
- Charging granularity and billing: Per blocks of 100 milliseconds, compared to by the hour (and sometimes minute) of other models.
Kubernetes/Knative and FaaS
Kubernetes and Knative are one implementation of “plumbing” behind FaaS. Kubernetes is an open source, container orchestration tool that is critical to the managing of cloud applications. Knative lets you run serverless within a Kubernetes cluster.
The combination of Knative and Kubernetes means you can take advantage of Kubernetes functions like monitoring, security, logging, and authentication and combine them with Knative benefits such as automated container build, full portability, and working across hybrid environments.
Creators of this technology believed developers should not have to choose between serverless and containers when building cloud apps. The goal was to augment the availability and consistency of containers with the powerful scaling and on-demand access of serverless.
The video "What is Knative?" provides more information.
FaaS and IBM
IBM Cloud Functions is IBM’s FaaS offering. IBM has been working with customers across various industries—including finance, automotive, insurances, manufacturing, etc.—to run production workloads on IBM Cloud Functions. ESPN Fantasy Football, which has more than 10 million daily active users, is adopting IBM Cloud Functions for their statistics dashboard, and The Weather Underground (part of The Weather Channel) renders all their radar maps using Cloud Functions. These and other use cases are described in the blog post “A Recap of the Key Advantages Offered by IBM Cloud Functions.”
IBM Cloud Functions is based on Apache OpenWhisk. OpenWhisk’s core is an open source project under the guidance of the Apache Foundation, so anyone can contribute their action code as building blocks to the repository. This means OpenWhisk is constantly growing and improving. OpenWhisk accelerates application development, which enables you to quickly build apps with action sequences. FaaS offerings also provide greater visibility into performance details for cloud functions.
IBM Cloud Functions also includes access to cognitive services like IBM Watson APIs within the event-trigger-action workflow. And, you pay only for what you actually use. Costs increase only as you run more load on Cloud Functions – billing is based on the time and memory required to execute functions.
Watch this video to learn more about how IBM Cloud Functions work, and check out our post, "Four Reasons Serverless FaaS on the IBM Cloud is Better Than Ever."
For more information on FaaS, sign up for the IBMid and create your IBM Cloud account.