I’m building a REST API for a mobile app. I’m considering using AWS Lambda (Serverless) instead of running a small T3.micro EC2 instance. Everyone says Serverless saves money, but I’m worried about "cold starts" and how the costs scale if the app suddenly gets 10,000 users. Is the complexity of Lambda worth it for a simple backend, or should I stay with traditional virtual machines?
3 answers
For a small API with inconsistent traffic, Serverless is almost always cheaper. With EC2, you pay for the instance every second it's running, even if no one is using your app. With Lambda, you only pay when code actually executes. Regarding cold starts, if you're using Node.js or Python, they are usually under 200ms, which is barely noticeable for most mobile apps. The "complexity" is actually lower because you don't have to manage OS updates, patching, or scaling policies. Lambda handles all of that for you, allowing you to focus entirely on your code.
Sharon, at what point in terms of "requests per second" does Serverless actually become more expensive than just reserved EC2 instances?
I use Lambda for all my side projects. The AWS Free Tier gives you 1 million free requests per month, which is impossible to beat with any virtual machine setup.
That 1 million free requests is exactly why I started with Serverless too, Derek. It’s perfect for testing the market without any financial risk.
Bryan, that's the million-dollar question. Usually, if your API is processing constant, high-volume traffic (think hundreds of requests per second 24/7), a Reserved Instance or Fargate might be cheaper. But for most apps that have "peak" times and "quiet" times, the Serverless model's ability to scale to zero when not in use provides a level of cost optimization that a fixed instance simply cannot match.