I’m using Ionic 2 and Firebase Auth/Realtime Data, but I’m finding that the amount of data being downloaded from Firebase is excessive, and after crunching the numbers, would be far too expensive for me. For example, I’m storing a list of friends as shown below:
Where the path is equivalent to this: /friends/[userId]/[friendId]
And the properties dn & fg mean displayName & following, respectively (I tried to abbreviate the property names to make the download size smaller).
In my Ionic app, I reference the following path: /friends/[userId] to get the list of my friends. In this case there are only 2 users and each user only has 1 friend. Using the “/friends/[userId]” path would just retrieve the single friend for the logged in user.
I can consistently reproduce subscribing to this path and the realtime database usage chart showing that I downloaded 1.9 KB of data each time. This occurs regardless of whether I use an AngularFire2 list or the firebase refs. While subscribed to that list, I can go into the realtime database web UI and manually change my friend’s display name to “Bob Tester2” and again it charges me another 1.9 KB of download usage.
I’m not a math major, but the data for one friend is significantly less than 100 characters, so I assume it would be downloading less than 100 bytes for each change.
Here is my code:
let uid = 'rSq28CjbWFRSmXoCE7aZZBkZKNR2';
let ref = this.db.database.ref(`/friends/${uid}`);
ref.on('child_added', data => {
console.log('got friend: ', data.val());
});
ref.on('child_changed', data => {
console.log('friend changed: ', data.val());
});
ref.on('child_removed', data => {
console.log('removing friend: ', data.val());
});
When running the app, my output is:
got friend: Object {dn: “Bob Tester”, fg: true}
And that’s 1.9 KB each time!
This is just a sample of the problem. I have other data in my database that all creates the same problem. Basically, opening my app and loading my 1 friend, and the equivalent of 3 twitter posts charges me 20 KB each time.
Is this the expected behavior for Firebase realtime data? I’m I doing something wrong?