Introduction to Function as a Service (FaaS)
Before we dive into Function as a Service (FaaS), let’s see what the journey has been before FaaS.
Physical Servers > Virtual Machines > Containers > Functions
Earlier Physical Servers were used to run applications. Though they offered good performance, they were meant to support the working of only specific applications only. If another application were to run on them, it would affect the workflows of both. The rise of Virtual Machines in 2001 allows enabling application-specific resources from physical machines to V M instances running. This decreased the infrastructure concerns related to particular applications on physical servers. Then Docker containers came, which provided a lightweight alternative to Virtual machines by encapsulating only application, and it is specific dependencies inside a container.
Functions make the developer’s process even more autonomous. Functions are code snippets inside the container which get executed based on some events.
For example, A function can be made which creates a database, and on creation, it populates that database with values. Without functions, developers would have to wait for database creation and then manually update the database.
FaaS enables the Serverless Computing by firing off bits of code, freeing the developer from managing infrastructure and enables to simply write business logic code.
Other Cloud Models
Apart from FaaS, we have other cloud models:
PaaS: Platform as a Service
PaaS provides a software development environment to clients by providing all software tools to developers in one place in an organized manner.
SaaS: Software as a Service
Here the provider does not expose Virtual machines or networks to the user; instead provides him with access to software services such as databases. So the client doesn’t need to worry about the OS and focuses on software.
IaaS: Infrastructure as a Service
Here the client is provided by full infrastructure such as networks, Virtual machines, etc. In other terms, it is called “Cloud Computing.”
What is Function as a Service FaaS?
FaaS is a cloud service execution model and uses functions for the purpose. As stated above, Function is a piece of code of business logic, more particularly, which is event-driven. That means that it gets triggered and performs its part on a launch of a particular event until the task is done.
Functions can be of various types such as :
- Function to process a web request
- Function for any scheduled job
- A function that executes manually.
Moreover, we can also chain functions, which means a particular function on completion can trigger another function to execute. For example, A function for web requests on completion can trigger any scheduled job function.
This way, the process becomes more autonomous.
Read more about Serverless Architecture with OpenFaaS and Java
List of Function as a Service (FaaS) Service providers:
- Microsoft Azure
- Amazon Web Services (AWS)
- Cloud Functions
Below is a sample example of an Azure function snippet.
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
log.Info("C# HTTP trigger function processed a request.");
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
return req.CreateResponse(HttpStatusCode.OK, "Hello " + data.name);
How does Function as a Service Work?
Anyone who wants to get the benefits of FaaS needs to use a cloud service provider to implement FaaS.
- In the FaaS model, developers are not concerned with infrastructure and service-related computing, and they are only concerned with writing functions.
- These functions on getting invoked will cause the cloud provider to bring up the server, and on the successful execution of the Function, the server goes down.
- These servers get available on demand when the Function invokes and goes down until the Function executes. Thus saving cost for the subscriber of cloud services as well.
What is the Serverless Architecture of FaaS?
Serverless architecture is a far broader concept than FaaS. With a large number of workloads now shifting to the cloud, cloud providers need to provide backend services like
- Load balancer configuration
- Cluster management
- Operating system to support the workloads etc
These are known as BaaS (Backend as a service). And serverless architecture comprises FaaS and BaaS.
For example, in databases, many BaaS solution providers provide data validation mechanisms so an application can use these at its backend to authenticate with the database. Now FaaS comes into play. Consider the case when a new record is inserted into the database. Using FaaS, a small function can be added inside the application container, triggered when a new record is added inside the database.
The serverless architecture makes FaaS more reliable and affordable. It promotes the trend to implement things as services and use API gateways to map HTTP requests with those functions.
Serverless Architecture offers huge advantages for companies seeking to transform at scale and support digital journeys.
Use cases of FaaS
One most effective use case of FaaS would be its ability to provide “on-demand” functionality. The “on-demand” functionality enables the powering down feature of any infrastructure leading to cut down the cost, and billing would drastically get lower. You can view the AWS (Amazon Web Services).
In terms of availability, security, and maintenance related tasks, these cloud provider servers are beneficial; otherwise, these things have to be manually managed alongside.
Simplified Developer Logistics
The development team loves Faas service as it simplifies application development, and sending updates to users becomes smooth. With server infrastructure fully optimized, software developers and teams can focus more on what they are best doing. This leads to faster development, faster updates, and response to customers.
Pro Tips for Adopting Function as a Service
Few questions you need to ask yourself before going for FaaS services would be:
- Will FaaS bring a positive impact on daily development workflow?
- Do we have the budget to afford FaaS services, and how it will lead to the efficient development of our project.
- What is the purpose of subscribing to FaaS services in our project?
- Which FaaS provider would best suit your purpose.
These are the few questions you need to keep in mind before implementing Function as a Service (FaaS) to your workflow.
In the end, it all comes down to you and your work environment. Whether FaaS will be suitable for your environment or not needs to be identified by you. Like every other workflow that works for a particular set of needs and fits in certain situations, the same is the case with FaaS.