Home > Software engineering >  Fierbase Realtime Database: Save costs by choosing short path names?
Fierbase Realtime Database: Save costs by choosing short path names?

Time:04-30

Firebase RTDB costs are, in contrast to Firestore, calculated by download size (and not by operation count).

When you get data, like in this pseudo code database.child(path1).child(path2).getData(), then it also gets the keys for every value (key-value pairs). And also each single path, including path1 and path2. The keys in the key-value pairs are actually also just paths.

Are these paths taken into the calculation of the download size for the pricing?


I'm aiming at this:

Suppose you load 1 million key-value pairs of this kind: Every value is a boolean. But each key is a 200-character long string.

Would it be cheaper if the keys would be 10-character long strings instead?

CodePudding user response:

Since the path names are sent from the server to the client, there is a cost associated with having longer path names. And I've definitely seen projects where they went with single-character key names to reduce that cost.

Whether it is worth choosing shorter path names purely for the cost savings, is something only you can determine for yourself.

Also consider if you app really should be reading a million key value pairs. Are you really going to show all of those to the user? In general: store the data close to what show on the screen to the user, and then only load data that you're showing in the current screen.

  • Related