Cloud & DevOps

AWS Lambda: When Serverless Actually Costs More

December 27, 2024 β€’ 2 min read β€’ By Amey Lokare

πŸ’° The Promise

Serverless is supposed to be cheaper. Pay only for what you use. No idle costs. Perfect for APIs with variable traffic.

So I moved my API to AWS Lambda. And my costs went up.

The reality: Serverless isn't always cheaper. Here's when it costs more.

πŸ“Š The Numbers

My API stats:

  • 10 million requests/month
  • Average response time: 200ms
  • Peak traffic: 100 requests/second
  • Average memory: 256MB

Traditional Server Cost

EC2 t3.medium instance:

  • Instance: $30/month
  • Data transfer: $10/month
  • Total: $40/month

AWS Lambda Cost

Lambda pricing:

  • Requests: 10M Γ— $0.20 per 1M = $2.00
  • Compute: 10M Γ— 0.2s Γ— 0.256GB Γ— $0.0000166667 = $85.33
  • Data transfer: $10/month
  • Total: $97.33/month

Lambda is 2.4x more expensive!

❌ When Lambda Is Expensive

1. High Request Volume

At 10M+ requests/month, Lambda compute costs add up quickly. Traditional servers have fixed costs.

2. Long Execution Times

Lambda charges per 100ms. If your functions take 200ms+, costs multiply.

3. Consistent Traffic

If traffic is steady, you're always paying. A server is cheaper at constant load.

4. Cold Starts

Cold starts add latency and cost. Frequent cold starts make Lambda inefficient.

βœ… When Lambda Is Worth It

  • Sporadic traffic: Low, unpredictable load
  • Short functions: < 100ms execution time
  • Event-driven: Triggered by events, not constant requests
  • Low volume: < 1M requests/month

πŸ’‘ Cost Optimization Tips

1. Use Provisioned Concurrency

Eliminates cold starts, but adds fixed costs. Only worth it if you have steady traffic.

2. Optimize Memory

Right-size memory allocation. More memory = faster execution = lower cost (if it reduces execution time).

3. Use Lambda@Edge

For simple responses, Edge functions are cheaper than regular Lambda.

4. Consider Fargate

For consistent traffic, Fargate can be cheaper than Lambda.

πŸ“Š Cost Comparison Table

Traffic Pattern Lambda EC2 Winner
Low, sporadic (100K/month) $5 $40 Lambda
Medium, steady (1M/month) $15 $40 Lambda
High, steady (10M/month) $97 $40 EC2
Very high (100M/month) $970 $80 EC2

🎯 My Decision

I moved back to EC2. For my traffic pattern (10M+ requests/month, steady load), it's 2.4x cheaper.

Lambda is great for some use cases, but it's not always cheaper. Do the math before you switch.

πŸ’‘ Key Takeaways

  • Serverless isn't always cheaper
  • High volume + steady traffic = EC2 is cheaper
  • Low volume + sporadic traffic = Lambda is cheaper
  • Do the math before you decide
  • Consider all costs: compute, requests, data transfer

Don't assume serverless is cheaper. Calculate the actual costs for your use case.

Comments

Leave a Comment

Related Posts