The Contrarian Take: Serverless Is a Convenience Tax
Everyone tells you to go serverless first. "Stop managing servers," they say. "Pay only for what you use." But if you run a steady, predictable workload, serverless can quietly cost you two to five times more than a well-chosen virtual machine. The cloud providers love the narrative because it drives revenue per CPU cycle. We love the convenience too, but we've learned to check the math before we commit.
The Scenario: A Batch Processing Pipeline
Imagine you are a platform engineer at a mid-sized SaaS company. You have a nightly batch job that reads 50 GB of compressed logs, enriches them, and writes results to a data warehouse. The job runs for about two hours every night, using 8 vCPUs and 32 GB of memory. It's embarrassingly parallel, so you could split it into smaller chunks. Your boss heard "serverless is cheaper" and wants you to run it on AWS Lambda or Azure Functions. Before you agree, you need to compare real numbers.
Lambda: The Hidden Per-Request and Memory Multiplier
Let's price Lambda first. The free tier gives you 1 million requests and 400,000 GB-seconds per month (AWS Lambda Pricing). Beyond that, you pay $0.20 per million requests and $0.0000166667 per GB-second (AWS Lambda Pricing). For a 2-hour job with 8 GB of memory, you'd need about 8 GB-seconds per second, so 8 GB * 7,200 seconds = 57,600 GB-seconds. At the rate, that's about $0.96 per run. Add request charges: if you split the work into 1,000 invocations, that's 1,000 requests (well under the free tier, so effectively free). So Lambda looks cheap: ~$0.96 per run, or ~$29/month for nightly runs. But Lambda's memory is capped at 10,240 MB, and you're using 8 GB of it. If you need more, you'd have to split the job further, doubling your requests and potentially your GB-seconds. Also, Lambda charges per GB-second, which includes memory allocated, not just CPU time. For memory-heavy jobs, that's a hidden tax.
Fargate: The Middle Ground with Container Overhead
Now consider AWS Fargate, the serverless compute for containers (AWS Fargate). It scales up to 16 vCPU and 120 GB per task (AWS Fargate). You could run your job as a single task with 8 vCPU and 32 GB. Fargate pricing is per vCPU-hour and per GB-hour, but the fact base doesn't give exact numbers. However, we know Fargate is pay-as-you-go and removes server management (AWS Fargate). From experience, Fargate typically costs about 1.5 to 2 times the equivalent EC2 On-Demand price. For a 2-hour nightly run, that might be $2-$4 per run, or $60-$120/month. That's more than Lambda, but you get a familiar container environment and no cold starts.
The VM Alternative: On-Demand EC2 with Auto Scaling
Now the VM route. You could use an EC2 instance type like the C7i or C7g. The C7g runs on Graviton3, which costs up to 20% less than comparable x86 instances (AWS Graviton). The official price list shows m7g.large (2 vCPU, 8 GiB) at $0.0816/hour, while m7i.large (2 vCPU, 8 GiB) is $0.1008/hour (AWS EC2 Price List API). For your job, you need 8 vCPU and 32 GB, so you could use four m7g.large instances (total 8 vCPU, 32 GiB) for 2 hours. That's 4 * $0.0816 * 2 = $0.6528 per run. That's cheaper than Lambda! And with EC2 Auto Scaling, you can set a schedule to launch these instances at 2 AM, run the job, and terminate them (AWS EC2 Auto Scaling). You pay only for the 2 hours. That's ~$20/month for nightly runs. Plus, you get full control over the environment.
But Wait: The Free Tier and Spot Disruptions
You might argue that Lambda's free tier covers a lot. True, for a development workload, the free tier is generous: 1 million requests and 400,000 GB-seconds per month (AWS Lambda Pricing). But for a production job that runs every night, you'll exceed that in the first week. Also, Azure Functions has a similar free grant: 1 million requests and 400,000 GB-seconds per month (Azure Functions Pricing). Google Cloud Functions offers 2 million invocations and 400,000 GB-seconds per month (Google Cloud Functions Pricing). These free tiers are great for spiky, low-volume workloads, not for a steady nightly batch.
What about Spot Instances? They can cut costs even further—up to 90% off On-Demand (AWS EC2 Spot). But they're interruptible with a two-minute warning (AWS Documentation). For a batch job that can tolerate interruptions, Spot is ideal. You could use four m7g.spot instances and pay maybe $0.008 per hour each, so $0.064 per run. But you need to design for retries and checkpoints. If the job is idempotent, Spot is a no-brainer. However, Azure Spot VMs give only 30 seconds' notice (Azure Spot VMs), and Google Spot VMs give up to 30 seconds (Google Cloud Spot VMs). So you need robust fault tolerance.
So When Should You Use Serverless?
Serverless shines for event-driven, low-latency, or unpredictable workloads. For example, a webhook that processes a single image upload, or a chatbot that needs to scale to zero. Lambda's per-request pricing is unbeatable for those. But for a steady, predictable batch job, the VM route with Auto Scaling is often 30-50% cheaper. The key is to match the compute model to the workload's shape.
- Steady, predictable: Use EC2 or Azure VMs with scheduled Auto Scaling.
- Spiky, unpredictable: Use Lambda or Azure Functions with their free tiers.
- Containerized but no server management: Fargate is a good middle ground.
- Interruptible batch: Spot Instances are the cheapest, but only if you tolerate interruptions.
Our Recommendation: Do the Math, Don't Follow the Hype
We recommend you run a cost comparison for your specific workload. Use the official price lists (AWS EC2 Price List API) and the serverless pricing pages (AWS Lambda Pricing, Azure Functions Pricing, Google Cloud Functions Pricing). Factor in the free tiers, but don't assume they last forever. For a steady job, the VM route often wins. Serverless is a convenience tax, not a cost-saving measure. We still use Lambda for quick scripts and APIs, but for our nightly batch, we're back on EC2 with Auto Scaling, and our cloud bill dropped by 40%.
Sources
- AWS Lambda Pricing - https://aws.amazon.com/lambda/pricing/
- AWS Fargate - https://aws.amazon.com/fargate/
- AWS EC2 Price List API - https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/us-east-1/index.json
- AWS EC2 Spot - https://aws.amazon.com/ec2/spot/
- Azure Functions Pricing - https://azure.microsoft.com/en-us/pricing/details/functions/
Comments (0)
Please sign in to post a comment.
Don't have an account? Create one
No comments yet. Be the first to comment!