Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Realtime Database Pricing with Query

I have a question about the firebase database pricing. I have about 400,000 rows in the leaderboard of my database, but in my app I just want to load the last 500 rows, so my question will I get charged for the 500 rows loaded when I run the query or will I get charged for all 400,000 rows.

Realtime database charges 5$ per gb stored and 1$ per gb downloaded. I did the calculation with Firestore and found that Realtime Database would be way cheaper if i get charged for the 500 rows and not the 400,000 rows.

I searched all documentation and have not found anything about queries: https://firebase.google.com/pricing https://firebase.google.com/docs/database/usage/billing

Can someone tell me if I get charged for just the 500 rows in my collection or for all the data in the collection and if there is a way to only get charged for the 500 rows maybe with security rules?

Here is my query code:

let queryRef = ref.child("Leaderboard").queryOrdered(byChild: "totalStars").queryLimited(toLast: 500)

How the database looks like. (It will have about 500,000 childs same as these and be loaded 200,000 per day, But I just want to be priced on the top 500 that I load and not the whole 500,000 each time a user loads the leaderboard is it possible?)

enter image description here

like image 781
jmapps9 Avatar asked Jan 25 '23 06:01

jmapps9


1 Answers

You will only be charged for the number of Firestore Documents corresponding to the result of your query (not to the number of docs in the collection).

So in your case a maximum of 500 reads, since you would limit the Query to 500 documents.


On the other hand, note that the Realtime Database queries are not shallow (while the Firestore ones are) and therefore if you query for a JSON node you'll get the entire tree under this node.

like image 147
Renaud Tarnec Avatar answered Feb 01 '23 11:02

Renaud Tarnec