0

What are the general limits, if any, of a very large frequently used collection (loads of writes and reads to the collection at the same time) in firestore?

Say you have an app where a user can scroll through a list of users. The information about each user is stored in a document in a collection. Now imagine a lot of new users is constantly created, and a lot of users is scrolling through the current list of users at the same time e.g. reading from the collection. Furthermore a lot of users searches the collection of users using different fields (name, interests, pets, etc.) and uses the indexes of Firestore.

If all of these things happened at the same time, would it affect the performance of firestore clientwise? Would it be necessary to create multiple smaller collections containing users? My question is to be understanded as an extreme case.

Casper Koch
  • 133
  • 9
  • 1
    https://cloud.google.com/firestore/quotas – couka Jan 27 '21 at 11:07
  • Does this answer your question? [Limitation to number of documents under one Collection in firebase firestore](https://stackoverflow.com/questions/48634227/limitation-to-number-of-documents-under-one-collection-in-firebase-firestore) – couka Jan 27 '21 at 11:09
  • My question is more concerned about a collection experiencing heavy workload than the max number of documents in a collection. – Casper Koch Jan 27 '21 at 13:00

1 Answers1

0

If all of these things happened at the same time, would it affect the performance of firestore clientwise? Would it be necessary to create multiple smaller collections containing users?

Yes. And yes.

Firestore is susceptible to hotspots on writes. If many clients write to the same collection and/or to the same index, you may experience delays in processing of those writes. For the exact limits, see the documentation on limits on writes and transactions.

Creating separate collections to shard out those writes is the common solution for this, although you can also accept the delay in processing.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • What if the application uses composite indexes to search the collection of users? Separating the collection into smaller ones would make it impossible to create composite indexes as far as i know – Casper Koch Jan 27 '21 at 15:13
  • To read/search across multiple collections you'd do a [collection group query](https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query). But in that case you need an index across those collections, which means your write throughput is limited across those collections as well. Hence the "Yes. And yes." at the top of my answer: Firestore has a real write-throughput limit, which comes from its guarantees (it guarantees immediate consistency of write operations across multiple data centers) and... physics (it takes real time to transport the data between data centers). – Frank van Puffelen Jan 27 '21 at 15:47