The hidden costs of serverless

Evaluating the real costs of serverless architecture is tricky

This article represents the opinions of Amiram Shachar, CEO of Spotinst. The author offers a competing product called Spotinst Functions.

Serverless architecture is the next step in the evolution of computing power. The reasons for taking the leap are clear:

  • You will save time: No more provisioning, managing, or thinking about how your application will scale up or down. Not only won’t you need to deal with implementation upon deployment, but all the time you spend dealing with the infrastructure afterwards will again be yours to spend on further innovation.
  • You can save money: In a Serverless world where you pay-per-trigger, you don’t need to write on/off scripts, plan reservations, or plan for spikes. You just pay for what you use.
Serverless is the next step in the evolution of computing power

Like the jump from on-premises to the cloud, the move to Serverless is more or less inevitable. Also like the jump from on-premises to the cloud — this move could come with some surprising bills.

Serverless costs is more than pay-per-trigger is a service built entirely on top of AWS Lambda and API Gateway by Eric Hammond, SVP Technology at CampusExplorer.

When running on AWS Lambda, the function costs for TimerCheck were incredibly low — at just $0.22 for over 2M requests and 300k+ seconds of compute. Sounds a lot better than paying for an entire server but only using part of it, right?

But Lambda functions came in at just under 2% of his total AWS cost.

After launching the services, he wrote about the pricing of AWS Lambda, concluding with a request to Amazon; ”please lower the cost of the API Gateway”.

Eric went on to say that “If you are reading this after November 2016, then the prices for these AWS services have certainly changed and you should not use any of the above numbers in making decisions about running on AWS.”

Well, the prices haven’t really changed.

What does Serverless really cost?

There are more costs to Serverless than just CPU and RAM — and for many users, the additional cost categories of API Requests, Storage and Networking will be the major cost drivers.

The 5 Cost Categories of Serverless

The Visible Costs

  • Requests: These costs tend to be around $0.2 per 1M executions across the board, across all providers
  • CPU & RAM: The $0.000067 per GB-second is pretty standard as well

The Hidden Costs

  • API Requests: Since many Serverless apps are heavy on API calls, this can get quite pricey at roughly $3.50 per 1M executions.
  • Networking: If you’re sending a lot of data out, you need to carefully review this category. At $0.05-$0.09 per GB-out and $0.1-$0.2 between VPCs/regions on AWS, it can get very expensive — very fast. In general, network costs are usually the hardest costs to track down.

While it might be worthwhile to consider the various free tiers across providers, most of these free tiers don’t discuss those “hidden” costs — networking, API requests, and storage.

The Unknown Costs

Some of the costs of Serverless aren’t all easily measured in dollars and cents.

Code maintenance
Serverless coding = more lines of code. As Twin Tech Innovations pointed out: “For each non-trivial route (piece of functionality) added to a software system, the number of lines of configuration code needed to maintain the project grows at a steep linear rate when using a serverless architecture.”

Comparing Lines of Code

“Someone has to maintain all of that. Someone has to ensure that issues are not introduced as changes are made to the configuration of one function and not accidentally ported to the others. Someone needs to ensure that code is not duplicated and that complexity and dependencies are managed.”

Cold starts
This isn’t the time to dive in deep, but it’s a main reason why some companies decided against going Serverless when evaluating Lambda. As Hannah Taub said, “100 milliseconds for startup alone starts to drag…when a user application needs a latency of less than fifty milliseconds.” These cold starts will likely disappear eventually, but for now, you’ve got to factor them in.

How to analyze the cost of Serverless

Let’s keep the cost analysis to the basics for now —each of these considerations have enough details for a much deeper dive.

Consider the basic pricing differences
An AWS Lambda function with 512 MB of memory costs $0.030024 compared to an On-Demand server with the same stats costing $0.0059. So when your CPU is being fully utilized all the time, running on Serverless may not be cost-efficient for your workload.

Project your API requests
API Gateway tends to be a huge chunk of your Serverless costs when you connect to a lot of APIs. The more API requests you make per trigger, the less savings you’ll see from the switch to Serverless.

Don’t forget data and networking costs
This won’t be different than a container running the same resources, but it won’t be less, either. The switch may not be worth it if data/networking are the largest chunk of your application’s costs.

Explore all the Serverless providers
There’s no shortage of alternative offerings, each with their own unique pricing advantages.

Serverless Cost Comparison

Assess the cost of extra code maintenance
It’s always hard to attach a $ value to something that doesn’t have one, but consider now how much these aspects mean to you — and how much extra time you or your team will spend making the switch to Serverless.

Utilize the free tiers
Every provider offers a free tier, sometimes enough for you to run smaller workloads for free. If you want to be super cost-efficient, you can take full advantage of the different free tiers by using them all. If you architect your Serverless apps properly, it can be a great opportunity to start unlocking yourself from your vendor.

Apart from the cost-savings in your initial Serverless apps, it also lets you start take advantage of the various features and efficiencies offered by different CSPs by running the right workloads on the best-fitting CSPs for that specific workload and its costs.

Serverless Free Tier Comparison

Ultimately, the transition to Serverless architecture offers huge potential in terms of cost and time savings. To avoid any surprises, it’s well worth your time to analyze the potential costs before diving into Serverless.