Search code examples
firebasegoogle-cloud-firestoregoogle-cloud-functionsgoogle-cloud-tasks

Firestore concurrent limitation while cloud task running


I am trying to use cloud task execute a cloud function for every minute. Just imaging there is a collection with 2 Million documents in firestore. So I am going to read this collection for every Minute.

Document 1-->
     PerformAt: 3rd of September 2021 at 09:00AM
     Status: Scheduled

Document 2-->
    PerformAt: 3rd of September 2021 at 01:00PM
    Status: Scheduled

Document 3-->
    PerformAt: 2nd of September 2021 at 03:00PM
    Status: Done

Cloud Function--->

const query = db.collection('tasks').where('PerformAt', '<=', now).where('Status', '==', 'scheduled');

In this case, It will read 2 million documents of where status is scheduled. My questions are,

  1. if I am going run this for every minute, will it effect to performance of my app?

  2. Only 1 Million concurrent users allowed per database, Hence Will that cloud function consider as 2 Million concurrent users or just one user?

  3. How much time does it take to read about 2 Million document?

  4. Also, I need to change Status as Done when PerformAt <= now. In this case, Firebase Only allow to writes 10,000 per database. What Can I do to overcome from this situation?


Solution

  • Please limit yourself to a single question per post going forward.

    1. Yes, any code you run will affect the performance of your app. but without knowing exactly what your code does it'll be impossible to say how it is affected.

    2. Each instance of a Cloud Function counts as one connection only.

    3. The performance of a query depends only on the number of documents (and their size) returned by the query, not on the number of documents in the collection. So if each minute only a few tasks meet the .where('PerformAt', '<=', now).where('Status', '==', 'scheduled') condition, then only those documents are read.

    4. The limit of 10,000 writes is per second. It is unlikely you'll hit this, but if you do there is no way around it (that's the nature of limits).