0
votes

I'm designing a REST API for my app on Firebase Realtime Database. I would like to know which of the two options would be better for me both from a point of view of cost and efficiency:

  1. Client writes the request directly on my database and the cloud functions' onWrite gets triggered and writes a response at an appropriate node which the client reads.

  2. Client sends a HTTP request with a request and Firebase Cloud Functions' HTTP trigger sends an appropriate response back to the client.

I expect to get around 300 000 API requests per month.

1
You said you are worry about cost. How many requests do you estimate to get per month? - RefaelJan
Multiple, but I would like to compare the cost between single api requests. Be it through method 1 or 2. - Arjun Ram
The volume would be very high. But the cost analysis doesn't depend on that right? It should depend more on the efficacy per trigger of function. - Arjun Ram
You will have to determine which is best for your specific use case. Without a lot more details, it's not possible to make a simple judgement call about which is better. I've explored the issue in depth (using Firestore instead of RTDB) in this post: medium.com/firebase-developers/… - Doug Stevenson
Thanks Doug! I'll look it up. - Arjun Ram

1 Answers

0
votes

Cost:

It is hard to know which is better since it is depend on your specific use. You can try to calculate it with firebase calculator https://firebase.google.com/pricing#blaze-calculator But from simple POV it seems that option 2 is better since in both options cloud functions do the same amount of calls, while in the first option you have also to pay for the DB

Efficiency:

In theory it seems that option 2 will be more efficient since it has less components for each transaction, while in both options cloud functions will have relatevely the same amount of work. Practically, you will know only if you test it.

In general:

Option 2 seems to be the right way. In this option you are using firebase in the right way the creators design it for. While in option 1 you are using firebase in non trivial way, which can lead to some bugs and can cause your system to be more complicated. Simplicity wins in most cases. Especially if more than one programmer will work on this system.