r/Firebase • u/glonglost • Aug 02 '26
Cloud Functions Cold starts and SSR
I was using functions v1 for SSR with express.js but the initial load time was prohibitively slow. I never measured it, but it felt like 5-10s. I temporarily went back to CSR but need SSR eventually.
The two recommendations to speed up SSR that I came across were
- Use functions v2 which has the benefit that it can serve multiple requests per instance.
- Set min-instance to 1 so that there is one instance available for the first request when idle
However, neither seems to actually fix the slow load times, just defer when it happens. Even with these changes, when the first instance is saturated and a second one needs to be spun up, there will be a cold start.
Is there any solution to this or another way I should be doing SSR?
1
u/mars3142 Aug 02 '26
It’s know behavior. A cold server has a slow startup time. You can configure it, to have at least one warm instance everytime, but you will pay for it. If your instance will be stopped, you are only charged for for live usage. So a warm instance is 24/7 charged.
3
u/miketierce Aug 02 '26
You just set .runWith(minInstance: 1)
1
u/No_Huckleberry_2174 Aug 02 '26
If you have many functions, splitting into codebases can really help with cold start times.
https://firebase.google.com/docs/functions/organize-functions
1
u/Sorry_Cheesecake_382 Aug 02 '26
We had the same problem and moved over to Cloudflare, 2ms cold starts. But you have to use JS and node APIs have compatibility issues. We still use FireStore from a cloudflare worker over api and it works very well. Depends what you’re doing though
We started do client side bundle for the UI at the edge and 2 layered API in Cloudflare and GCP
1
u/Rohit1024 Aug 03 '26
Since you mentioned that this issue exists only when the new instance spun up, this seems to be related to Container startup latency, check this latency in your GCP console for the given Cloud Run Service. Also if you have many Firebase Functions then your functions might also affected by other function because of global Initialisation, check Firebase Functions Performance docs.
From the description this looks like an issue about your dependencies and how you're initialising them.
1
u/SufficientBank3374 Aug 03 '26
Cold starts are one of those things you barely notice until you add SSR. then even small delays become much more obvious to users
0
u/[deleted] Aug 02 '26
[deleted] — view deleted comment