1

I want to use the Firebase callable functions to run checks on the back-end but I am worried about the cold-start. For instance, I want to check if a user has sufficient credits to download a certain product but I would like to avoid users waiting 10 seconds or more before this promise gets resolved or rejected, and running these checks from the front-end is no option as anyone could bypass them.

Is there a way to do provisioning for a selected group of callable functions on Firebase so that the whole experience doesn't feel slow and frustrating for users? Many users if they have to wait 10 seconds (even if its just for the first time) might give up using this service I want to sell...

1 Answer 1

2

Is there a way to do provisioning for a selected group of callable functions on Firebase?

Yes, as explained in the doc, you can set a minimum number of instances for a given Cloud Function with the runWith parameter, as shown below:

exports.myCallableCloudFunction = functions
    .runWith({
      // Keep 1 instance warm
      minInstances: 1,
    })
    .https.onCall((data, context) => {
      // Cloud Function code
    });

You can have more than one instance warm by passing the desired value, e.g. minInstances: 3.

Note that "a minimum number of instances kept running incur billing costs at idle rates. Typically, to keep one idle function instance warm costs less than $6.00 a month" (excerpt from the doc).


Note also that you need to configure each Cloud Function with this option, AFAIK you cannot apply it to a group of Cloud Functions.

Sign up to request clarification or add additional context in comments.

3 Comments

Hey, thanks I totally overlooked this! Indeed it kinda kills the price-point of serverless functions but maybe if I keep this to a minimum it could work. People are also suggesting using corn jobs on express routes to "ping" some functions and keep them warm every x amount of time...do you think this would be a valid alternative?
"do you think this would be a valid alternative?" => not a 100% reliable solution... It may happens that the Cloud Function platform kills your Cloud Function instance between two pings. I would give a try with one warm instance.
Oh, that would suck thanks for saving me a massive headache when trying to figure this out for myself!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.