Skip to main content
Serverless

Serverless Isn't Cheaper: How to Stop Overpaying for Lambda

Everyone says serverless saves money. It doesn't for steady workloads. Here's how to use Lambda and Fargate without burning cash—and when to switch to containers or EC2.

Here's the contrarian truth: serverless is the most expensive way to run a steady workload in the cloud. Yes, it's convenient. Yes, it scales to zero. But if your function runs for more than a few minutes a day, you're likely paying a premium compared to a simple EC2 instance. The pay-per-use model sounds great until you do the math—and most people never do. This article is for developers and architects who've bought into the serverless hype and are now staring at a Lambda bill that makes no sense. I'm going to walk you through a practical, step-by-step process to figure out whether serverless is actually right for your workload, and if it is, how to configure it so you don't overpay.

1. Know Who This Is For

If your workload is truly event-driven—like processing S3 uploads, handling API requests with long idle periods, or running occasional batch jobs—serverless can be a legitimate choice. But if you have a service that runs 24/7, like a web API or a data pipeline, serverless is probably the wrong default. The free tiers are tempting: AWS Lambda gives you one million requests and 400,000 GB-seconds per month (AWS Lambda Pricing). That sounds generous, but it only covers about 44 hours of a 1GB function running continuously. After that, you're paying $0.20 per million requests and $0.0000166667 per GB-second (AWS Lambda Pricing). A 1GB function running for a full month (2,592,000 seconds) would cost $43.20 in compute alone—not counting requests. Meanwhile, a t3.micro EC2 instance in us-east-1 costs $0.0104/hour (AWS EC2 Price List API), which is $7.49 per month. You could run that instance 24/7 for less than a fifth of the Lambda cost. So, if you're running a steady, always-on service, serverless is a luxury you might not afford.

2. Measure Your Actual Usage

Before you make any switch, you need numbers. Don't guess. Look at your cloud monitoring dashboard and find your function's average memory allocation, execution time, and invocation count per day. Also check your container tasks if you're using Fargate. For example, if your Lambda function uses 512MB and runs 10 million times a month, each execution averaging 200ms, your GB-seconds are 10,000,000 * 0.5 * 0.2 = 1,000,000 GB-seconds. That's 2.5 times the free tier, so you'd pay for 600,000 GB-seconds, which at $0.0000166667 each is $10.00, plus $2.00 for the 10 million requests (since 1 million are free). Total: $12.00. That's still less than a dedicated instance, but if your invocations are long—say, 10 seconds each—your cost explodes. The key metric is CPU-time, not invocation count. If your function runs for more than a few seconds on average, you're likely better off on a small EC2 instance or a container.

3. Compare Serverless Options: Lambda vs. Fargate vs. Azure Functions vs. Google Cloud Functions

Not all serverless is created equal. AWS Lambda is the most popular, but AWS Fargate lets you run containers without managing servers, and it scales up to 16 vCPU and 120GB of memory per task (AWS Fargate). If you need more memory or want to run a containerized app, Fargate might be a better fit. Azure Functions offers a similar free tier to Lambda: 1 million requests and 400,000 GB-seconds per month (Azure Functions Pricing). Google Cloud Functions gives you 2 million invocations and 400,000 GB-seconds per month (Google Cloud Functions Pricing). So the free tiers are comparable. But the real difference is price beyond the free tier: Google charges $0.40 per million invocations and $0.0000100 per GHz-second, which is different from GB-second (Google Cloud Functions Pricing). You need to compare apples to apples. For a steady workload, none of these will beat a reserved instance. But if you need burstable, event-driven scaling, serverless is the way to go. Just know what you're paying for.

Provider Free Tier (per month) Beyond Free Tier Max Memory
AWS Lambda 1M requests, 400K GB-seconds $0.20 per 1M requests, $0.0000166667 per GB-second 10,240 MB
Azure Functions 1M requests, 400K GB-seconds Per-second resource consumption and executions 1,536 MB
Google Cloud Functions 2M invocations, 400K GB-seconds $0.40 per 1M invocations, $0.0000100 per GHz-second Not specified

The table above shows the key differences. Note that Azure Functions rounds memory usage up to the nearest 128MB, and the minimum execution time is 100ms (Azure Functions Pricing). That means a short, small function might cost more than you think. Google's GHz-second pricing is tricky because it depends on CPU allocation, not just memory. So, when comparing, calculate your actual cost using your workload's specific profile.

4. Use Spot Instances for Stateless Workloads

If your serverless functions are stateless and can tolerate interruptions, you might not need serverless at all. You could run the same code on EC2 Spot Instances, which can be up to 90% cheaper than On-Demand (AWS EC2 Spot). Spot instances are ideal for big data, CI/CD, web servers, and containerized workloads—exactly the kinds of things people often run on Lambda. The catch is that they can be interrupted with a two-minute warning (AWS Documentation). But if your application is fault-tolerant, you can handle that. For example, if you're processing a queue of messages, you can use Spot instances as workers. If one gets terminated, another takes over. This is a classic pattern. So, before you commit to serverless, ask yourself: can my workload run on a spot instance? If yes, you could save a lot of money. For a steady workload, a spot instance might be even cheaper than a reserved instance, but it's not guaranteed to be available. So, you need to mix spot with on-demand or reserved capacity for reliability.

5. Consider Graviton and Savings Plans

If you do decide to use EC2 instead of serverless, you can cut costs further. AWS Graviton-based instances cost up to 20% less than comparable x86 instances (AWS Graviton). For example, in us-east-1, the m7g.large (Graviton3) costs $0.0816/hour compared to the m7i.large (x86) at $0.1008/hour (AWS EC2 Price List API). That's a 19% saving. And if you commit to a Savings Plan, you can get even more discounts. Compute Savings Plans offer up to 66% off On-Demand, and EC2 Instance Savings Plans up to 72% (AWS Documentation). Reserved Instances can save up to 75% (AWS Documentation). So, if you have a steady workload, combining a Graviton instance with a 3-year Compute Savings Plan could reduce your compute bill by over 80% compared to On-Demand. That's a huge difference from serverless. Even if you need the flexibility of serverless, consider using Fargate with Savings Plans—you can purchase Savings Plans for Fargate too, which might be worth it.

6. What Can Go Wrong: The Cold Start and Scaling Trap

Here's a warning: serverless has hidden pitfalls. Cold starts can add latency, and if your function scales up unexpectedly, your bill can spike. For example, a single misconfigured loop could trigger millions of invocations. Also, Azure Functions has a maximum memory of 1,536 MB (Azure Functions Pricing), so if your function needs more, you can't even use it. And on Google Cloud, the free tier includes only 200,000 GHz-seconds, which is less than the GB-seconds (Google Cloud Functions Pricing). So, you might run out of free tier faster than you think. The worst part is that serverless pricing is opaque. It's easy to lose track of what you're spending. I've seen teams get a surprise bill because they didn't set up budget alerts. So, before you go serverless, set up billing alerts and monitor your usage daily. If you see costs climbing, you need to act fast.

7. The Bottom Line: Move Steady Workloads Off Serverless

If you have a workload that runs more than a few hours a day, you're better off on a container or an EC2 instance. Use serverless only for truly event-driven, short-lived tasks. For those, Lambda's free tier is generous, and you might not pay anything. But for anything else, do the math. A simple t3.micro instance at $0.0104/hour (AWS EC2 Price List API) costs $7.49 per month. A 1GB Lambda function running 24/7 costs $43.20. That's a 5.8x difference. Even if you add managed Kubernetes with EKS, the control plane is free, and you only pay for the nodes (Azure Free Account, but EKS also has no control plane charge). So, you can get the benefits of containers without the management overhead. My recommendation: start with serverless for prototyping, but move to containers or EC2 for production if you have steady traffic. You'll save money and have more control.

Quick tip: Before you migrate, use the AWS Pricing Calculator or Azure's pricing page to estimate your monthly cost for both options. It takes 10 minutes and could save you hundreds of dollars.

Sources

  • AWS Lambda Pricing - https://aws.amazon.com/lambda/pricing/
  • AWS EC2 Price List API - https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-east-1/index.json
  • AWS Fargate - https://aws.amazon.com/fargate/
  • Azure Functions Pricing - https://azure.microsoft.com/en-us/pricing/details/functions/
  • Google Cloud Functions Pricing - https://www.srvrlss.io/provider/google-cloud-functions/
  • AWS EC2 Spot - https://aws.amazon.com/ec2/spot/

Share this article:

Comments (0)

No comments yet. Be the first to comment!