Serverless or Containers?

I've read about people switching over from Docker (container) to AWS Lambda (serverless) but what scratches my head is, are there any performance (latency and cold start especially) difference? I mean, both are quite similar, so there shouldn't be any difference at all?

Let's say you create a single function that returns a certain calculated number, and you deploy this as Lambda function and to docker. My guess is that both should perform that function equally fast, am I wrong?

My question: Why should you prefer one over the other?

My understanding is that AWS Lambda functions are just like Docker except they're "smaller" and stateless and only runs when the function is being called.

Did you find this post useful? Show some love!

It’s a matter of preference, for example where I work we do this:

  • each developer runs Xubuntu
  • all development happens on LXD based containers, with the files injected
  • all testing is done via Gitlab CI (self hosted)
  • all non-global but project specific tests are run on docker inside the development container, and gitlab is interacting with them directly when applicable
  • Jenkins builds the releases, containers, and runs tests when necessary

In our situation a serverless approach would be unfathomable. I’m all in favour of serverless when it makes sense.

In my opinion, when it makes sense:

  • simple application
  • simple deployment pipeline
  • not hard pressed if files override customer specific
  • no complex or time consuming functionality needs to be run continuously

When it doesn’t make sense:

  • development on local machine (LXD or docker here!)
  • complex or multi-Layer deployment cycles
  • remote vs local
  • cost efficiency versus developer time versus reward (pick two, if you want cost low, and high reward, don’t expect to have lots of free developer time, etc)

AWS Lambda does have cold start every 4 hrs. The first request to hit after cold start will have increased latency. (Apparently they removed the 5 minute idle cold start.)

Here is an interesting article on cold start perf.

Aside from that, lambda nodes are basically just containers (on Amazon Linux distro) under the covers... running python, node, jvm, dotnet core, etc. In between function executions, the container is frozen (background processes will freeze too, if you started any).

Whereas Docker containers are still running between executions. This allows you to run stateful workflows (i.e. when entities are too large to load/save on every request). And also keep background tasks running between API executions. Those two things are not supported in Lambda. You can actually keep some data in memory between executions, but the container may be thrown away at any time. So it could be useful for caching things (caches can be rebuilt), but for stateful workflows a thrown-away container would lose data.

When you get into auto-scale docker containers, you are probably going to run into some of the same issues as lambda (ephemeral containers). Plus you have to manage a cluster. So it starts to make sense to just use Lambda instead.

Classic DEV Post from Aug 9

How do you style components with React Native?

Styled components are great for React, but do they work with RN?

READ POST
Follow @stenpittet to see more of their posts in your feed.
dev.to is now open source!
View Announcement Post View GitHub Repo
Jay Sitapara
Helping people understand Serverless | Technology Consultant @Simform | Life essentials- Dog and Coffee | Connect with me on Twitter to talk more about Serverless.
More from @jsitapara
Moving from EC2 to AWS Lambda: Our Journey to Serverless
#discuss #aws #awslambda #serverless
Why we chose serverless over containers?
#serverless #discuss #docker #aws
Trending on dev.to
What's your origin story?
#career #learn #webdev
What are your favorite terminal apps or scripts, to use for productivity?
#discuss #python #bash #productivity
Deploying Next.js on AWS Lambda
#serverless #nextjs #devops #react
I Failed as a Developer. And so did you.
#opensource #career #webdev #discuss
Containerizing a Node.js API & Using Docker with Kubernetes and Minikube
#docker #kubernetes #minikube #node
How old have you been when you started programming and what was your first project?
#discuss
Style your Terminal better by mastering these settings 🀩
#terminal #productivity #tools #webdev
What part of your first dev job were you least prepared for?
#discuss #career