Introduction
FaaS stands for function-as-a-service where server-side logic is written by application developers, but unlike traditional architectures, it’s run in stateless cloud compute containers that are event-triggered, ephemeral, and fully-managed by a third party. As a type of serverless architecture, FaaS allows you to build and run application functionalities without thinking about server infrastructures. All three of the big cloud providers, namely Amazon, Google, and Microsoft, offer this type of service. Currently, Amazon’s AWS Lambda is the most popular implementation.
Before I dive deeper into FaaS, you may be curious to know what Serverless Computing is about.
In short, it means that you do not need to deal with the complexity of managing a physical server even if your app/website uses one.
According to AWS, Serverless enables you to build modern applications with agility and lower total cost of ownership. What this means is that you could focus more on the core product instead of worrying about managing and operating servers. This reduces the overhead for you so that you can spend more time and energy on developing products while enjoying a faster time-to-market.
In this article, I will discuss the benefits and drawbacks of FaaS, and how you may start using it for your next project.
FaaS in Action
With a traditional architecture, a finite number of servers are responsible for handling all the requests. As more people start using the service, the servers will eventually get so busy that users wouldn’t be able to get their results back in time. For example, a user may get stuck on the checkout page for a long time because the server never responded due to a high workload. In contrast, FaaS architecture is highly scalable based on demand. In the example above, BuyGrocery and GetGrocery are application functionalities. As the number of users increases(more Buy/Get requests), the cloud system will create as many copies of the function as needed to meet demand and handle user requests in a timely manner. When demand drops, the application automatically scales down to save resources. This is called Dynamic Scaling, and it is a benefit of using FaaS. Unlike traditional architecture, no server needs to be provisioned for running applications functionalities. They are always on the cloud, available to handle requests whenever you need it.
Benefits
Improved Developer Velocity
Being a type of Serverless architecture, FaaS allows you to focus more on developing cool features rather than having to deal with the complexity of managing a server. This typically means you can finish the product earlier.
Easy to scale
Scalability is very important for software systems. Being scalable means your application is capable of handling a growing amount of work. FaaS is a serverless way to execute modular pieces of code in a container. A container is simply a piece of software that virtualizes the operating system and runs the code inside a sandbox-like environment. This makes it easy to scale code by horizontal scaling(running more instances of the sandbox). Additionally, you do not need to worry about peaks in traffic because your cloud provider usually handles this for you by automatically scaling your function on demand.
Cost efficiency
You only pay for the computing time that you have used and do not need to waste money over-provisioning cloud resources.
Use Any Programming Language
You can use almost any programming language you like to write the FaaS code. For instance, AWS Lambda allows you to use Node.js, Python, Java, Ruby, C#, Go, and PowerShell.
Drawbacks
Lack of Control Over Physical Hardware
Outsourcing your infrastructure to a third party may impose some challenges for debugging and handling unexpected events. It also means that any server-side optimization is impossible because you do not have control.
Difficult to Perform Integration Testing
It can be difficult to incorporate FaaS codes into a local test environment because they run on the cloud.
Stateless
Being stateless means no state can be stored with the function. All storage operations must take place externally(e.g. use a database). This may be a problem for functions that solely rely on local storage.
Time Limit
Most cloud providers set a strict timeout for FaaS code. For example, the maximum timeout for the AWS Lambda function is 15 minutes. The lambda function will be terminated, regardless of the state of the function, after a timeout.
One-size-fits-all?
In reality, modern applications will be composed of a mix of these solutions: functions, microservices, and long-running services. FaaS is primarily used in the event-driven execution model where a function is triggered in response to an event. Common FaaS use cases are data processing, IoT services, mobile or web apps.
How to get started using FaaS
You must register an account with a cloud provider in order to start using FaaS. The cloud provider that I am currently using for my projects is AWS. Using free tier should suffice for most small projects. The best way to get started using AWS Lambda is by following this official tutorial. Alternatively, depending on the provider you choose, you may also consider Azure Functions or Cloud Functions. You may read about their differences here.
Summary
FaaS stands for function-as-a-service. It is a category of cloud computing services that provides a platform for developers to build, run, and manage application functionalities without having to deal with the complexity of maintaining infrastructures. It provides agility, scalability, and cost-efficiency for building modern applications. Some challenges in using FaaS include lack of control over server hardware, difficulty performing integration tests, lack of local storage, and strict function timeout. Although FaaS is great for many application purposes, it is not a one-size-fits-all solution. If you want to get started with FaaS, I recommend AWS Lambda as a starting point.
References
Eyk, Erwin van. “Serverless Anwendungen Und Services in Der Cloud.” Amazon, Software & Support Media GmbH, 2019, aws.amazon.com/serverless/.
Hendrix, Roger W. “Lambda.” Amazon, Laboratory, 1983, aws.amazon.com/lambda/.
What Is FaaS?, www.redhat.com/en/topics/cloud-native-apps/what-is-faas.
“Serverless Architectures.” Martinfowler.com, martinfowler.com/articles/serverless.html.
Yorumlar