I am building an app with Firebase Cloud Firestore. In the app, a query will be listened to, returning 10s-100s of documents. The expected frequency of change of these documents is less than once every few minutes. Most of these documents would be under 10KB, but some might go up to 300 KB (1 MB is the largest allowed document size).
The Cloud Firestore best practices docs read,
For the best snapshot listener performance, keep your documents small and control the read rate of your clients. The following recommendations provide guidelines for maximizing performance. Exceeding these recommendations can result in increased notification latency.
Limit the individual document payload to 10 KiB/sec (Keep the maximum document size downloaded by an individual client under 10 KiB/second).
What would happen if the payload occasionally exceeds 10KB/sec when the large documents update – would it just delay the notification, or would it affect other database operations for this client (or others as well?), or do something like throwing an error/crashing the app?
CodePudding user response:
In all cases, regardless of the size of the payload, there is going to be the cost of transferring all the document data across the network. It stands to reason that larger documents take longer to transfer, especially over slower connections. If you keep your documents small, then they will transfer faster, and your listener will appear to perform more quickly.
Nothing specifically "bad" happens when you transfer large documents. The client app is just going to have to wait longer (i.e. experience worse performance) in those cases. The guideline to keep the payloads small is a just a general performance-boosting improvement. If you are observing poor performance due to large documents, it might be a good idea to split up the data between collections and transfer only what's necessary at the moment, or implement a cache so that unchanging data doesn't get over-fetched.
You should, of course, perform your own benchmarks to see how your listeners are performing. It's common to throttle network speeds to simulate slower (often mobile) connections in order to observe performance at these speeds, which should help you better understand what your users might be experiencing while using your app.