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 May 9

What Makes an Environment Inclusive?

What makes a work environment inclusive to you? What does it take?

Follow @kaydacode to see more of their posts in your feed.
Jay Sitapara
Helping people understand Serverless | Trying to be more Productive | Life essentials- Dog and Coffee | Connect with me on Twitter to talk more about Serverless.
More from @jsitapara
Why we chose serverless over containers?
#serverless #discuss #docker #aws
How do you secure your Functions?
#discuss #serverless #functions #aws
Trending on
Startup CliX: RC1 with Private Games & Mobile UI
#pushercontest #javascript #game #aws
Is Javascript a compiled language?
#discuss #javascript #compile
Hi, I'm Kyle. I just wrote a book on learning AWS, I love helping others and working on side projects. AMA!
#ama #aws
Why should we care about containers for development
#microservices #docker #containers
Startup CliX: Finally some Gameplay
#pushercontest #aws #javascript #game
Playing With Apache Storm On Docker - Like A Boss
#storm #java #docker #data
Devs, what tools do you use to keep track of API changes?
Explain Higher Order Component(HOC) in React.js like I'm five
#explainlikeimfive #beginners