Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore: Joins vs Firestore pricing

How do you perform cheap joins with Firestore?

In Firebase, I would .map() the response and get the additional data based on a foreign key stored on each item. However, considering the pricing model of Firestore where you pay per reads, this appears to be too expensive. What do you think?

In my case, my relationship is many actions to a handful of categories (circa 5 - 7). Each action belongs to one category.

What would be the best practice for this case? Should I keep doing it like in Firebase? Or should I fetch both collections independently and join them in Javascript?

Jakub

PS How do you actually work with the reference data type? It is unfortunately not described in the documentation.

like image 902
Jakub Avatar asked Oct 14 '17 06:10

Jakub


People also ask

Is Firebase firestore expensive?

Cloud Firestore includes a no-cost tier to help you get started at no cost. After you exceed the usage and storage quotas for the no-cost tier, you're charged for the database operations you perform, the data you store, and the network bandwidth you use.

Which is cheaper firestore or Realtime Database?

Conclusion: All these database storage options can be used separately or all at once depending on the need of the application. In case of applications with more read/operations, Realtime Database is recommended and in case of large number/size of data, Firestore is recommended because of a cheaper rate.

Is Firebase firestore free?

Firestore offers free quota that allows you to get started at no cost. The free quota amounts are listed below. If you need more quota, you must enable billing for your Cloud Platform project.

How is firestore billed?

When you use Cloud Firestore, you are charged for the following: The number of documents you read, write, and delete. The amount of storage that your database uses, including overhead for metadata and indexes. The amount of network bandwidth that you use.


1 Answers

Cloud Firestore, as you noted, charges for each document read. This is based on the number of documents returned to you when you make a query. It does not matter how many individual requests you make to get the documents (assuming each request returns >= 1 document). So it will be cheaper for you to do the map() method than to fetch all documents and join them in memory, since you will be reading fewer documents from the backend.

If you share more about your data model (I can't picture it in my head) there may be a way to reduce the need for joins by duplicating some data or leveraging queries.

like image 144
Sam Stern Avatar answered Oct 04 '22 22:10

Sam Stern