DEV Community

loading...

Stop using AWS Lambda for everything!

Dan Dascalescu
Immigrant entrepreneur, formerly at Google and Yahoo! in Silicon Valley. Founded Blueseed, the startup community on a ship, and a few tech startups. Running the Quantified Self Forum.
Updated on ・2 min read

This is my reply to a reddit Explain Like I'm Five thread about Lambda vs. regular servers in the cloud (EC2, or VPSes).


There's another MAJOR con to Lambda: the warmup cost. It may take AWS a while (>5 seconds) to "cold-start" your function if it wasn't recently running, which means you have unpredictable startup times, and unacceptably high startup times.

Imagine you're building an app in which users can create, modify, read and delete items. You build an API (GraphQL or REST) with functions like createItem, and run each on Lambda.

Imagine an API call to createItem when a user creates a new item in your app. Since this is not a frequent operation, the createItem function needs to be warmed up. So it takes 5 seconds for the Lambda function to actually process the request. And if there's a problem creating the item (invalid values or whatnot), the user will have to wait 5+ seconds until they get an error, or are sure the item creation succeeded.

This is unacceptable.

Unfortunately, Lambda is such a cargo-culted technology that junior devs use it for everything "because it's cool".

So they use it to run servers that should be up all the time and respond fast, e.g. API servers like the one I described. And because of the Lambda cold-start problem, they end up using... Lambda warmup plugins! Which basically call all your Lambda functions all the time to "keep them warm".

What's the point then?

Why not run your API server on a real machine that,

  • is always running so you have predictable response times
  • responds in only the time required to actually process the API call (no 5-second "warm-up" cost)
  • and costs you only $5/mo?

It's not that hard to install Node or PHP or whatever language you need, and to configure the system to automatic safety patches and upgrades. (These things literally take one command each on Linux, and the extra devops knowledge you'll learn by figuring these things out will be well worth it.)

AWS provides those too (they's called Lightsail), but the concept has been around for 20+ years. DigitalOcean and Linode are the best known providers of these "Virtual Private Servers", which are basically computers in the cloud you can access like any real computer. You can scale those too, with load balancers or EC2 Auto Scaling.

Good use cases for Lambda are long-running operations that happen unpredictably and don't need to respond quickly. Netflix used it to transcode videos.

Discussion (0)