Is Serverless Computing Really Cost-Effective?

Afsheen Mujtaba
6 min readMar 17, 2021

Serverless computing is perhaps one of the most exciting developments in the evolution of cloud computing. This organic progression in cloud computing is a profound shift in IT solution execution. Serverless computing is proving beneficial to developers, enabling them to focus on coding rather than infrastructure.

Many companies opt for serverless computing since it looks so cheap. However, is it as cost-effective as it seems? In this article, we’ll take a closer look at serverless computing and see how its cost really compares to more traditional cloud computing.

Understanding FaaS Architecture

To clearly understand the pricing model, let’s look at the architecture of function as a service (FaaS). In the FaaS category of cloud computing, infrastructure is offered to customers to develop, run, and manage their applications without managing the server. Using FaaS, developers don’t have to set up application stacks for the code to run on the server. Instead, developers only focus on running the application, saving energy and budget.

To run an application using FaaS, you split it into smaller functions, resulting in a microservice architecture. New functions are spawned as needed, and scaling takes place at the function level. Also, a single function’s crash does not take the whole application down. Managing the server is the service provider’s headache, not the customer’s.

The service provider takes care of the application’s scalability, and developers are free from writing scaling policies or defining how machine-level usage translates to application usage. The cloud service is responsible for the maintenance, security updates, and availability of the cloud.

Pay-as-You-Go Service

The hosting pricing model has shifted from per-month using servers to per hour in infrastructure as a service (IaaS) to, finally, per function in FaaS. Now, server providers offer FaaS pricing models to attract customers. It’s a pay-as-you-go service. If you don’t request the function, it sits idly without costing you. The service provider only bills you when the code runs. The duration begins when the code executes until it returns or terminates. The service provider maintains application scaling.

AWS Lambda and Azure Function Pricing

Amazon Web Services (AWS) Lambda and Azure Function are affordable. One million invocations cost only twenty cents. If you examine the pricing model in detail, the price per function in February 2021 is US$0.00001667 for AWS Lambda and US$0.0000002 for Azure Functions.

However, this is only the cost of the function. This price does not reflect the operation’s total cost. When combining the other functions associated with running the operation and the time taken to complete the function, the cost may be much higher than you expect.

IaaS versus FaaS

Most businesses using cloud services prefer IaaS. Although IaaS is cloud-based, the customer manages the cloud. The service only rents out servers, virtual machines (VMs), networks, and storage. The customer manages the cloud, provisions hardware for running the app, and installs the apps.

In some cases, relying solely on provision-based computing is not possible.

A Surge in Demand

The difference between the two services becomes apparent when there is a sudden surge in demand. In IaaS, the application is provisioned to handle moderate workload fluctuations, and at times you must provision additional instances to handle sudden loads. In such situations, it takes more than one server to deliver your application in the different availability zones, making it impossible to reduce the cost.

This increase in the number of compute instances results in a higher per hour price while resource use goes down. To keep the load going on the server, cloud companies offer cost reductions and future provisions. However, it seems an impractical solution in the long run as most companies have used their reserved space, a situation similar to a server-based model.

Here, FaaS proves beneficial. FaaS provides out-of-box scalability and can be used across many resources at much lower prices.

GB-Sec Pricing Model

Calculate cost per function by multiplying memory size in gigabytes (GB) and function execution time in seconds to get a number in GB-sec, where GB-sec is the measurement of allocated memory used over runtime. After you use up your allotment on the free tier, the service provider charges the fixed rate of the service.

The above pricing model clarifies that for 1 million invocations with a run time of 500 ms and allotted memory of 128 GB, AWS Lambda only costs $1.25, which is unquestionably economical.

AWS’s On-Site Calculator

To calculate the pricing of serverless computing, AWS provides an on-site calculator. It helps calculate the cost by usage according to the region. For FaaS, AWS offers detailed guidelines using a pricing model. The onsite table shows the allocated memory cost, ranging from 128 MB to 10,240 MB, in 1MB increments.

Enough of the theory. Let’s discuss a real-world example. Assume we are a DevOps engineer assigned to deploy an API. We have two options: either use Lambda functions or set up an EC2 server that will serve our API. Even the most basic API hosting requires some architecture to expose the functionality to serve the request and persist data.

Take the AWS Simple Monthly Calculator example, which lists a Ruby on Rails application that can serve 100,000 page views a month. According to the example, the app is served through one load balancer with two web and application servers and other AWS services. As we can clearly see, the EC2 servers cost over 50 percent of the total bill, which is, at the time of writing, $559.30 out of a total of $96,459. Plus, we still need someone to manage this architecture, so human monitoring is required along with all the alerts placed through AWS CloudWatch. We also need to review this architecture if our number of requests increases from 0.1M to, let’s say, 10M per month.

However, let’s assume we decided to initially host this API on AWS Lambda, with AWS API Gateway providing the HTTP façade. As Lambda pricing is calculated in GB/s, our Lambda functions have allocated memory of 1GB. The duration average of function invocation is 3 seconds for the same 100,000 requests that we discussed above. The AWS Lambda and AWS API Gateway cost $5 and $11.15, respectively.

In this case, no human monitoring is required to scale this architecture. The architecture also accommodates any possibility of a sudden increase in the number of requests. So, if the requests suddenly increase from 0.1M to 1M, all we need is to contact the AWS server to increase the default concurrent execution limit, which is 100 by default, to the number that suits our needs.

When to Choose FaaS

So, when does FaaS become cost-effective? FaaS is ideal for when developers need to run code quickly without worrying about infrastructure issues like scaling. It’s also cost-effective for tighter budgets as the user is only charged when the code executes. It becomes a better choice for processes like extract, transform, load (ETL), or time-based apps to replace the monolithic design with smaller functions, only executing and paying for the running function.

Also, keep in mind no app can run on FaaS alone without support from other non-functioning elements, which are the amount of control over the running of function, cost, and application workload characteristics. Since the total price of a function is a multiple of allocated memory in GB and time to execute the function, the product varies considerably if any variant changes. A simple solution to keep cost under control is to monitor the two parameters continually. If the traffic and workload are predictable, opt for EC2 spot pricing rather than the Lambda function.

Although serverless computing supports a wide range of applications, it has its limitations. If you run an application structured to use IaaS, you’ll probably be charged much higher than expected. To use FaaS, first understand its architecture. You need to redesign an app into smaller functions, as microservices. Only those required functions run, instead of the whole app, saving you money.

Conclusion

We now have a better idea of how serverless computing costs compare to traditional cloud costs and when to use one versus the other. Armed with this information, you can take a closer look at your own architecture to see if you can save time and money by switching to FaaS.

To learn more about the different cloud computing options, check out the IBM Developer website.

--

--