0

In Firestore or Realtime Database, how many active users can listen for changes to the same document simultaneously? For instance, if 1000 users are subscribed to updates on one dokument will all users reliably receive notifications when that field is updated? Are there any limits to the number of listeners per document or per field, especially in terms of scalability?

  const documentRef = doc(fireStore, 'app-version', 'GDqbs283dl4lwOncr6WT');
    const unsubscribe = onSnapshot(
      documentRef,
      (docSnapshot) => {
        const data = docSnapshot.data() as { appVersion: string } | undefined;

        if (data?.appVersion) {
          setLocalAppVersion(appVersion);

       //...
       // if the app's local ver is diffrent then we have a new update
        }
      },
      (error) => {
        errorHandling(error, 'useSessionHandler onSnapshot');
      }
    );
  }, []);
  
  
  // Rules 
   match /app-version/{documentId} {
      allow read: if allowIfAuthPremium(request,userId) // only premium users are illigible.
      allow write: if false; // Deny all write operations
 }

1 Answer 1

1

Firebase's Realtime Database allows up to 200,000 simultaneous connections per database instance. See the documentation on Realtime Database limits for this and much more info.

Firestore has no documented limit. There is of course a physical limit, but it's much (seriously: much) higher than 1,000. See the documentation on Firestore limits and quotas for actual documented limits.

subscribed to updates on a single field within a document

There is no way to subscribe to only updates to a single field in a document in Firestore.

3
  • Do you mean this is a bad idea? The field has the app version, and once I increment it, it is supposed to trigger a notification for the users online who are listening to the field. The issue is that it is a web app, and I tried using FCM. The problem with FCM is that it does not support mobile due to push API compatibility issues, now if this is not a good idea would you recommend some other approach ?
    – Richardson
    Commented Jul 7 at 3:46
  • 1
    I didn't say anything about it being a good or a bad idea, as the question doesn't contain nearly enough information to allow that. But your question said you were gonna subscribe to a single field in a document, which isn't possible. ¯_(ツ)_/¯ Commented Jul 7 at 3:51
  • I Edited the question I meant that one doc will include the version data and all the user that are online will all listen to that doc .. once I have a new version build and pushed to hosting then I will change the ver num triggering the client listener to inform user about an update being available.
    – Richardson
    Commented Jul 7 at 7:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.