Search code examples
serverlessserverless-frameworkserverless-architecturecold-start

Do serverless functions install modules every time they are called?


Do server-less functions install modules every time they are called?

I am trying to understand how serverless functions really work. I understand that serverfull is basically a computer that executes code and that the server code runs on it 24/7 unless it is stopped for some reason. On the other hand I understand serverless code just runs when it is called. Where is this code stored? When I call a function in a serverless application does it install the modules (for example from npm) everytime I call the function? Is this what causes cold-start delays?

I understand that serverfull is like my computer running code. How can I describe serverless using the same analogy?

My Questions:

  1. Do server-less functions install modules every time they are called?
  2. If there is no server, where is this code stored in serverless?
  3. I understand that serverfull is like my computer running code. How can I describe serverless using the same analogy?

Solution

  • No, the dependencies are a part of the deployment artifact (e.g. a ZIP file or container image in the case of AWS Lambda), so they do not have to be installed on each invocation.

    I understand that serverfull is like my computer running code. How can I describe serverless using the same analogy?

    That's not going to be a perfect explanation, but hopefully, it fits your analogy. Imagine that your computer is sleeping, but there's another computer that can receive requests and wake up your computer whenever it receives a new one, so it can be run on your computer. After it finishes running, it goes back to sleep. But instead of a single computer, there are many of them that can be brought from sleep in a matter of milliseconds. Hope that makes sense.