Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit rate of data reads from Firebase?

I would like to limit the rate of data reads per user from the Realtime Database. There are good ways to limit writes like described here but I can't find any solution on how to limit data reads.

Can this be done with Security Rules, Cloud Functions or can I limit it somewhere in the Firebase account? I have checked the documentation but can't find the answer.

like image 632
Dave Avatar asked Feb 03 '19 22:02

Dave


People also ask

How do you reduce the number of read operations in cloud firestore?

This means that Cloud Firestore will try to retrieve an up-to-date (server-retrieved) snapshot, but fall back to returning cached data if the server can't be reached. This is how we can reduce the number of reads in Cloud Firestore, by forcing the SDK to use only the offline cache and get the data only upon request.

Can Firebase handle 10 million users?

The limit you're referring to is the limit for the number of concurrently connected users to Firebase Realtime Database on the free Spark plan. Once you upgrade to a payment plan, your project will allow 200,000 simultaneously connected users.

What are the Realtime Database limits in Firebase?

256 MB from the REST API; 16 MB from the SDKs. The total data in each write operation should be less than 256 MB.


1 Answers

This applies to both Realtime Database and Firestore, except with different terminology. (Location == document)

You won't be able to do this without also writing some value at a location in the database every time a read is performed. You can't write a location in a security rule, and you can't force the client to write at the same time as a read.

Even if you were able to write a location in a rule to use in a rate limit, you would then have to read that location for every read that must be limited, and that kind of defeats the purpose of a rate limit (since they could continue to try to read a restricted location in a way that just causes more reads to happen).

like image 176
Doug Stevenson Avatar answered Sep 24 '22 02:09

Doug Stevenson