On first invocation of the Firebase function I create a mysql connection pool (which is expensive) and store it in global scope. This works fine as long as there is a single instance serving requests. Assuming multiple functions instances can exist under load, what’s a good practice to prevent numerous such pools from getting created?
2
Answers
There is a specific section in the Cloud Functions documentation: "Use global variables to reuse objects in future invocations".
Cloud functions scale up to 1,000 instances per region.
SQL connections scale up to 32,000+.
Practically speaking, you’re not going to run into upper limits on your db connection(s).