10

The main advantage of serverless architecture is said to be that such programs do not need a dedicated server to run continuously. Then are invoked on a request and stop on exiting the function.

This means that a serverless program will have to be quick to start, for being responsive. How does then it handles time consuming actions such as database connection? Does it connect to database everytime or does it manage the database connection separately to function invocations like it is done in server applications?

2 Answers 2

9

Since a serverless app keeps no state between runs, it can't maintain a database connection pool. Serverless apps really face the same constraints as 90's CGI scripts. In general, a permanent server process will be able to outperform a process-per-request or container-per-request architecture because the server does initialization once, not once per request.

Serverless programs are not a great fit for latency-sensitive tasks like serving a website. They are better suited for sporadic background tasks that you don't want to run on your main server, without having to manually manage and load balance extra application servers. They may also be a decent fit if developer productivity is far more important than low-latency responses.

2
  • Excellent points. I'd also suggest that one major advantage that drives folks to serverless is the cost. If you're paying a provider (e.g. Amazon) based only on the # of requests, and are not paying to keep an idle server running, you'll save money especially during the startup phase.
    – Paul
    Aug 26, 2017 at 13:22
  • 2
    @Paul The main advantage of serverless is the convenience (PaaS vs. IaaS). Safely administrating a server is a skillset most devs (me included) don't have. I'm certain there are some scenarios where serverless is noticeably cheaper. But virtual private servers start at $5/mo which is very competitive, to say it lightly. Especially considering that a VPS has far less restrictions, allowing you to run arbitrary software and permanent services. This is a bit of an apple to oranges comparison. In one model you are paying for an idle server, in another you are paying for repeated startup time.
    – amon
    Aug 26, 2017 at 13:57
4

It depends.

The behind the scenes implementation of the lambda runner is going to affect this. We can see that in AWS the container might be reused.

http://docs.aws.amazon.com/lambda/latest/dg/lambda-introduction.html

So we could see connection pooling/reuse for some requests at least. Also we should consider the database itself and how it treats incoming connection requests.

This kind of question for me underlines some of the problems with 'serverless' its still very new and immature, so the details haven't been hammered out.

We should always remember that serverless doesn't mean no servers. If the rate at which you call a lambda is high enough, you may effectively have several servers, or 'containers' running.

In practice the start up time and resources such as IP addresses of lambdas can be a real issue. Perhaps as they mature a consensus of how to run them will appear and these problems will get solid answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.