Problem
The first Firebase call from the server takes ~ 15 - 20X more than subsequent calls. Although this is not a problem for a regular server that calls Firebase, it can cause problems with a serverless architecture using Amazon Lambda / Google Cloud Functions.
Questions
- Why is the first call so much slower? Is it related to authentication?
- Are there any workarounds?
- Can I do some user-initiated data calculations in Firebase DB using Amazon Lambda / Google Cloud Function and return the results to the client within 1-2 seconds?
Context
I plan to use the server architecture with Firebase as a repository of my data and Amazon Lambda / Cloud Functions, complementing Firebase with some server-side computing, for example. search for other users. I intend to run functions through HTTP requests from my client.
One of the problems I was experiencing was the long time it took to first firebase a call from the server. When testing some code on my laptop, the first listener returns in 6 seconds! Subsequent calls are returned in 300 to 400 ms. The data set is very small (2 - 3 pairs of key values), and I also tested it by replacing the observers.
In comparison, calling the Google Maps API from my laptop takes about 400 ms to return.
, . 15-20X .