Firebase Database Bandwidth Calculation
Solution 1:
So, back to the high bandwidth consumption. It has to do with Query
of Firebase Database. I have a query below when new user sign up.
QuerypriceQuery= getPricesRef().orderByChild("firebaseID").equalTo(myFirebaseID);
This was the beginning of my nightmare beause I did not set .indexOn
for that database. Read the official Firebase documentation here. The documentation regarding Query
is very poor. It only states that performance will be poor without index, but never mention about the bandwidth:
Based on the statement above, my assumption was that without .indexOn
, a query to Firebase may take longer to reply, since Firebase server may take longer to provide the search result.
However, as answered in Firebase database bandwidth usage when read with Query, the whole database is downloaded first from Firebase and then sorted and queried on Client's side! I guess that's what they meant by realtime client libraries can execute ad-hoc queries without specifying indexes.
As my database grows, each user sign up begins to consume higher bandwidth by downloading the whole prices
database. Towards the end, it was consuming ~800kB per user for just signing up. So make sure to use .indexOn
always!
Solution 2:
I found the bug. It is completely unrelated to the above question, but I'm documenting it here to help other users. So first, to answer my own questions.
Question (1) - Yes. That estimate of 480kB per session should be quite accurate.
Question (2) and (3) - The bandwidth consumed by Firebase should be lower than those recorded by Android Device Monitor. I contacted the support team and got the following reply.
For your bandwidth questions, the GB downloaded only measures the amount of data being sent by the Firebase database to your client app. This means data retrieval to your application.You might want to check the following links for more information:
Hence, deducting some overhead, the actual bandwidth should be slightly lower.
Post a Comment for "Firebase Database Bandwidth Calculation"