Firebase Cloud Function - Promises : Is there any limitation to the number of 'promises' that can be added to Promise.all()?

Viewed 226

So the Promise.all() does make out lives simpler.

But is there any limitation on the number of promises that can be added to 'Promise.all()'

i.e. Is there any limitation on the size of the array 'promises' in the following code:-

const promises = [];

    snapshot.forEach(doc => {

        **some code**

        promises.push(
            docRef.set(newData, {merge: true})
        );

    });

    return Promise.all(promises);

----------------------------------------------------------------------

Further Clarification:

I'm using this Cloud Function to update all users on my App.

Model DB Structure: Users/userId

Since the number of users is small, I'm not facing any issues for now.

But, as the number of users grows I'm concerned if I may hit some limits..

And as per the issues pointed out by:

1) david - browser's maximum concurrent web requests slowing things down

2) herohtar - limited memory available to your function

These two issues suggest that, there might as well be some limits.

So, can anyone point to the official doc for the same or Anyone from the Firebase team, if you guys can throw some light on the same.

1 Answers

If this function has to scale up to massive numbers of users, you are almost certainly going to have more issues exceeding the limits of memory and time in your function before you exceed any limits on the number of promises. I strongly suggest carefully thinking if you really want to load and perform N tasks in a function where N can be very large. This is not the sort of thing Cloud Functions was made for.

If you really need to perform N tasks in a scalable way, and you must use Cloud Functions, consider breaking your work up into manageable, predictable sizes, and shard the work out to multiple function invocations.

Related