I am currently learning Firebase Cloud Functions and wanted to understand if the express app is always running, my assumption is that it is always running on the Firebase platform otherwise how does it handle a request?
CodePudding user response:
Your Express app on Cloud Functions runs in a container, and the default behavior is to spin down that container after there have not been any requests for a while (the exact period is undocumented). Since you're only paying for the time it's actually actively processing requests, otherwise Cloud Functions would end up with lots of containers that nobody is paying for.
When a new request comes in when there is no container instance, or while all the existing containers are busy, Cloud Functions spins up a new container to process that request, which it then will also shut down when it's been inactive for a while.
Since spinning up the container takes some time, you can configure Cloud Functions to keep a certain minimum number of containers active. But I'd usually recommend only looking at that when you're actively experiencing performance problems due to the startup time of new containers, as you'll pay (a lower amount) for each container that is kept active while not processing a request.