Naman Tayal
Naman Tayal

Reputation: 1

How to minimize cloud firestore database reads for a kind of social network platform

I am trying to develop a react native app in which a user can generate a post and that post can be seen by anyone in the feed on their devices.

So for this, I am creating a new document for each new post created and using a realtime listener for syncing those requests on each device.

The problem with this approach is that for each fetch of the document from firebase it will charge for 1 read and the generated post needs to be fetched on each device, i.e. for each post, there are a lot of reads.

For eg - If 10,000 users are using the app then for each post, there will be almost 10,000 reads. If every user generates 1 post then the situation worsens.

How can I minimize the reads for this scenario?

P.S. - I am new to firebase firestore

Upvotes: 0

Views: 338

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317487

It's not clear to me what sort of answer you're looking for, but there is one simple fact that can't be changed - each document you need to read on the client will cost one read operation. There is no way to work around this. There are no batch or bulk reads that let you reduce the cost of a document read.

You can take advantage of the local persistence layer to act as cache, but that comes with limitations, and you will have to figure out on your own if that makes sense and how to implement it.

You can always try to cram lots of data into a single document, but that will only cause you problems later as you approach the maximum size of a single document.

Upvotes: 1

Related Questions