Is a runtime released after functions in the runtime return responses? Can I reuse the cached state or resources from a previous invocation?
Function Compute runs each function inside a container. After the function returns a response, the container is not released immediately. Instead, it stays alive — frozen and waiting — in anticipation of the next invocation. A container is released only after it receives no requests for a period of time, typically anywhere from a few minutes to tens of minutes, depending on the platform's scheduling algorithm.
A container can also be released if its host goes down. Because of this, you cannot assume that a warm container will persist indefinitely.
What you can safely cache
Initialize the following resources outside your function handler so that subsequent invocations in the same container can reuse them:
SDK clients and API clients
Database connections
Configuration values loaded from environment variables
Static assets that do not change between requests
Reusing these resources reduces cold-start overhead and optimizes performance.
What you must not depend on
Do not write code that assumes cached data will always be present. A container can be replaced at any time — when it has been idle too long, or when its host goes down. When that happens, all in-memory state is lost.
Design your function handler to work correctly even when starting from a cold container. Treat cached data as a performance optimization, not a dependency.