How to reduce the number of read operations in Cloud Firestore?

Alex Mamo
Firebase Tips & Tricks
3 min readJan 23, 2020

--

As you already probably know, Cloud Firestore is a flexible, massively scalable, cloud-hosted, NoSQL, real-time database for mobile, web, and server development and it’s is optimized to store large collections of small documents. When we use Cloud Firestore, we are always charged for the number of reads, writes, and deletes that we perform. So when talking about the number of reading operations, sometimes, there might be some situations when we are billed for read operations that actually might be avoided. So when we perform a query against a Firestore collection, in which the documents are constantly changing, every change of a document it will cost us a read operation. That being said, if a document is changed, for instance, five times, we are charged with five read operations. You might think, there are only five operations, it’s not too much. Hold on, try to think if you have a query that returns 50 results and each document is changed five times in a very short time. In this case, you’ll be charged with 250 read operations, which is a little bit much. Assuming that you might have several collections in your project, that number of read operations can grow even more. So let’s take a concrete example.

Let’s say we have a section in an application where we display a list of 50 hot selling products. Each product is represented by a…

--

--