The Dark Side of Serverless: The Hidden Costs of AWS Lambda
Serverless Architecture is a great product, you can scale & cost efficiency in one time. But we have some new issues. What is? Yah your serverless hide some cost from you :)
What does Serverless Really Cost?
Not only pay as CPU and RAM, you will cost more than it. Let's part it by 2 sections: The Visible Costs & The Hidden Costs.
The Visible Costs:
- Requests: These costs around $0.2 per 1M executions
- CPU & RAM usage: $0.000016 per GB-second is pretty cheap as well
- Temporary Storage: This small charge $0.000000037 for every GB-second, not really hurt you
The Hidden Costs:
- API Requests: When you use Serverless, your apps will use heavy on API calls. This is quite pricey at roughly $4.25 per 1M executions.
- Networking: You will charge $0.09-0.12 per GB-out, it can be very expensive when you careless about data out.
- Other Coupling Product: If you use serverless architecture, may you need Cloudwatch Log, S3, SNS, SQS, DynamoDB, MemoryDB, etc.
Let's make assumption,
- No Free Plan
- Traffic 1 million
- Average RAM is 512MB
- The Average process is 100ms
- Average Output 10KB
Component | Formula | Price | % |
---|---|---|---|
Requests | $0.2 x 1,000,000req / 1,000,000 | $0.2 | 3.27% |
CPU & RAM | $0.000016 x 512mb / 1024 x 100ms / 1000 x 1,000,000req | $0.8 | 13.09% |
Storage | $0.000000037 x 512mb / 1024 x 100ms / 1000 x 1,000,000req | $0.002 | 0.03% |
API Requests | $4.25 x 1,000,000req / 1,000,000 | $4.25 | 69.57% |
Networking | $0.09 x 1,000,000req * 10KB / 1024 / 1024 | $0.858 | 14.04% |
Total | $6.11 | 100% |
Are you think Lambda is expensive? You can see the biggest cost is Network-Based.
Source Code Maintenance
The Paradigm on Serverless is 1 function for 1 worker. When you need a complex system for your apps, you need many functions. Serverless code = more lines of code.
Need someone to maintain it all. He/She needs to ensure everything working well. More lines of code = more complex to maintain.
Waiting for a Cold Start
When you need the lowest latency, maybe you can't. Every Serverless provider has a cold start, just because they need to allocate your code into their instance. When your code optimizes to 1-digit millisecond, you can get more than 100ms for cold start only. Some providers have a solution to "provision" it, but the cost isn't as cheap as their marketing.