How much realtime updating Firestore is possible? - firebase

There is a group chat with 1000 people. These people listen to real-time updates to the same collection. If these all 1000 people keep chatting fastly like for an hour. All huge chat data could be updated without any problems? And also real-time listener could reflect all data?

If you attach a real-time listener to a collection, all devices that are listening to that collection will be notified in real-time.
All huge chat data could be updated without any problems?
Yes, there will be no problem with that.
And also real-time listener could reflect all data?
Yes, it will.
The real-time listeners won't create a problem, but trying to keep an entire collection of 1000 users in sync, might create. So most likely you should consider implementing pagination, so you can load those messages in smaller chunks, otherwise, it will be some kind of costly.

Related

Firestore Snapshot Listeners: Realtime Updates Best Practices and Churn Rate

According to Firestore's Best Practices docs (below), one should avoid adding and removing snapshot listeners in quick succession. The docs state, "snapshot listeners should have a lifetime of 30 seconds or longer." However, because a snapshot subscribe and subsequent unsubscribe is controlled by the user's actions (e.g. navigation to and away from a particular page), it may not be possible to always to keep a connection open for more than 30 seconds.
As an example, my app has an Account Details page. The page has one listener the subscribes to the main details (i.e. Account Name, Primary Address, Primary Contact, etc.). The page also has several tables (e.g. Locations, Inventory, Purchase Orders, etc.) each of which has their own listener.
That being said, would it be problematic if my users navigate between several Account Details pages very quickly (since each page will be opening and closing its own set of 3-5 listeners)? If it is problematic, what type of issues will this create for my app? For instance, would Firestore simply slow down temporarily? Or could there be bigger issues with data consistency (i.e. where the snapshot temporarily shows old snapshot data while waiting for the new snapshot to prime)?
Here's what is stated in Firestore's Best Practices documentation:
Avoid frequently churning listeners, especially when your database is under significant write load.
Ideally, your application should set up all the required snapshot listeners soon after opening a connection to Cloud Firestore. After setting up your initial snapshot listeners, you should avoid quickly adding or removing snapshot listeners in the same connection.
To ensure data consistency, Cloud Firestore needs to prime each new snapshot listener from its source data and then catch up to new changes. Depending on your database's write rate, this can be an expensive operation.
Your snapshot listeners can experience increased latency if you frequently add or remove snapshot listeners to references. In general, a constantly-attached listener performs better than attaching and detaching a listener at that location for the same amount of data. For best performance, snapshot listeners should have a lifetime of 30 seconds or longer. If you encounter listener performance issues in your app, try tracking your app's listens and unlistens to determine if they may be happening too frequently.
https://firebase.google.com/docs/firestore/best-practices#realtime_updates
Rapidly adding and removing listeners due to such user action won't create technical problems, but it just means you'll be using more resources than you'd ideally like.
If you imagine that many users may follow this same click path that you describe, consider running a single query that gets you the data for all those screens in one go. That might mean you need a different/additional data structure, but on the other hand also means you have less churn in setting up/tearing down listeners.
But again, this is not a technical limit in any way. It is merely an observation of patterns that the writers of that documentation have seen get the best value out of Firestore.

Firebase -- exceeded quota number of reads

I have created a simple firebase webapp, which is subscribed to listen for changes within a collection in firestore. As there are only 3 items in that collection, I was wondering how it was possible to reach the quota limit of 50k reads a day. I did leave the app running on localhost while I was away from my computer, which I am assuming is the reason that it reached the daily quota limit. But how was it possible to do that?
Basically, I have one page on my webapp that is subscribed to my collection in firestore. I then use that data retrieved to display it on the page.
As I said, there are only 3 items in the collection I am subscribed to. How does the subscription work? Is it constantly reading the database to watch for changes, or does it only do a read request when the collection changes (a doc being added or removed, for example)?
PS I have not even published this app to the web, so I don't think it's even possible for read requests to be coming from another computer.
You got a loop there
useEffect is triggered whenever products changes, and you are calling setProducts in the useEffect itself.
So i'm thinking that this has consumed all your daily quota.

Can I adjust the Firestore Listener Frequency?

I have a Flutter & Firebase app that provides users with price updates on the dashboard on the main screen. It does this with a Firestore Snapshot Listener, but my read count is flying through the roof (I'm at 203 reads and just 1 device is connected)... This info will only change once a month, and it really doesn't need to keep checking for updates at all times.
Is there a way to setup the listener so that it checks less frequently for updates? Or perhaps, can I setup a Firebase In-App Messaging system with which I send the price out and the app just saves and displays it?
Or is there any efficient solutions?
Since the Listener (which you do not show, so we can't even help you there) ONLY triggers when there is an update to the documents (NOT on a schedule) something is updating the collection you are listening to. 203 is not particularly high over a few days - how long has your app been running? Have you been restarting the app frequently? Most Listeners will give you a result at least once when you initialize them - i.e. when you start the app. There is no "long-term global memory" like that.
A listener will always receive updates as soon as they becomes available. This can't be configured. If you want a different update frequency, you should instead schedule that yourself within the app, and use get() to poll the database as often as you need. You can also use FCM on your backend to push updates to the app, if that works for your case.

Firebase Document Write Limit

Hey so with my current feed database design, I am using Redis for the cache for super-fast reads, which are routed through my Google Cloud Functions. The Redis database handles all post data and timeline updates, which is great and all, but I forgot one of the most considerable caveats to this. Firebase Firestore only permits one document write per second, meaning that if I have a document that stores the post data (post_id, user_id, content, like_count), the like_count would be impossible to track with the possibility for many likes per second. Does anyone have any solutions to this?
You can shard your counter among multiple documents and query them in aggregate as needed.
You can also try Cloud Tasks queue to smooth out the write frequency. It will add considerable complexity to the system, but is really the only genericized way in GCP to manage the rate of some work. This might not work out the way you need, however.
If you use Cloud Tasks, your task will need to be configured with a rate limit, and it will have to deliver the document data to write to yet another function or other HTTP endpoint that will perform the write.

Are active listeners a good solution to populate UI changes once a day?

Using Cloud Firestore as a database for my application.
The labels/images I use in the app are updated about once a day, if that, and are populated from the data saved onto my Firestore database.
I'm trying to weigh the pros of having a one-stop solution to my having my UI updated automagically and not having to deal with unreliable network on the user's behalf, and the cons of my application being a drain on both, the user's battery life and their data connection.
There are no documentations I can find on this, and the only source I have is this Firecast video where I can find some confirmation for the former use case.
I'm trying to figure out if I should go with manual fetches or active listeners.
If someone know about any documentation on this topic, I'd be thankful for it.

Resources