Does Firebase throttle multiple REST requests from the same server? - firebase

We have an application that is running on Heroku and uses Firebase for data. There are some instances where we have to do some logic that require multiple nested Firebase calls (if method 1 succeeds, create object with method 2) and so on. Unfortunately, they seem to be a little more in-depth than what a transaction method on the client side could accomodate.
We are relying on the REST api to do these functions server-side, but have run into issues when stress-testing that they are frequently timing out (especially when issuing a PATCH request).
However, if we run the same test on a different server with the same code and Firebase database, they succeed no problem.
Is there any throttling going on for multiple requests from the same environment?

Related

Caching in firebase

I have my app hosted in firebase and using cloud functions to fetch data from a third-party API. This cloud function is HTTP triggered and runs whenever client-side requests data. I want to reduce cloud functions calls (as it is currently on Blaze plan), so thinking to add caching in my app.
What are the caching strategies I can use on the client (web browser) as well as server-side (Node.js)?
Overall I want to reduce cloud function calls to minimize costs, so that on every client request, cloud function doesn't need to be called, instead the client can fetch data from cache.
Should I use firebase real-time database for storing data from third-party API and update this in firebase over a period of time, so that data is up-to-date? Data on the third-party side doesn't change frequently.
Whether fetching data from real-time database (as mentioned in point 3 above) instead of cloud function calls would eventually reduce costs?
If you host your Cloud Function behind Firebase Hosting, you can write a cache header in every response and manage the cache behavior of Firebase Hosting that way. Allowing the content to be served from Firebase Hosting's CDN may significantly reduce the number of times your Function gets executed, and thus its cost.

Difference between Vue router and express, are both needed (especially when using Firebase)?

I'm trying to build a relatively simple application that has several different views, requires authentication, collects some user data, stores it in a database, and needs backend logic to manipulate that data and spit it back out to the user in a view.
The stack I've decided on is Vue for the frontend, with Express and Node for server side logic and Firebase for some of their services (namely auth, firestore, storage).
I haven't been able to find any examples of this stack (Vue, Express, Firebase) anywhere (I have however found Vue/Express or Vue/Firebase examples). My question is whether or not Express is obsolete here in that I can use Vue router to do my routing. Is the difference that one does the rendering server-side?
You could use Cloud Functions for Firebase as your backend and then limit your stack to Vue.js and Firebase.
From the doc:
Cloud Functions for Firebase lets you automatically run backend code
in response to events triggered by Firebase features and HTTPS
requests. Your code is stored in Google's cloud and runs in a managed
environment. There's no need to manage and scale your own servers.
For your specific need: "backend logic to manipulate that data and spit it back out to the user in a view." you have several possible approaches:
You manipulate the data with Cloud Functions (in the back end), write the results of this manipulation to the Real Time Database and setup some listeners in your Vue.js frontend (with the on() method) that will refresh your front end upon changes in the database
Use some HTTPS Cloud Functions that you call, from your Vue.js front-end, as REST API endpoints. You can use Axios for example. See the doc here.
One advantage of the first solution is that you can easily, by default, rely on the database security rules, while it would need some more extra work in the second case.

Does the firestore sdk use a connected socket to make its requests or individual http requests?

I'm using the react native firebase sdk and am wondering about how the underlying network calls are implemented. When making firestore get queries, is the sdk just keeping a socket open when it's initialized and make requests over the open socket, or does it make individual http requests to an endpoint?
Specifically I'm looking for an efficient way to get a batch of documents (profile thumbnail properties given a batch of profile ids), and I saw an answer that said that firebase calls are pipelined so calling the gets in parallel is efficient. However, I'm not sure if that applies to firestore as well.
The Firestore SDK uses gRPC to communicate with the server. This is the same layer that many of Google's other Cloud products use under the hood. It is quite different from the Web Sockets communication layer that the Firebase Realtime Database relied on.
Digging into the code it seems like the "real time" part of firebase uses websockets. The database module also has a dependency on
faye-websocket

Undo Write operation if offline

I am attempting do the following
write a document to server.
wait for the success event and check for metadata to confirm if its written to server
if it is not written to server even after the time out (using a timer) undo the write operation.
this is for WEBRTC calls so if a user attempts a call but was offline and closes the app since it did not succeed. after a long time the receiver would receive a call and would be weird.
There are no undo operations in Firestore. The client SDK tries doesn't really give any way to discern if the app is online or offline - it simply tries its best to service the requests that you give it via the API.
If you want to perform some operation while only online, then use Cloud Functions to make an HTTP request to backend code that performs the actions you want. If the app is offline, the HTTP request will obviously fail, and you can decide what you want to do from there.

How do I communicate / trigger a Webtask from Firebas?

In an interesting blogpost about 'Firebase Authentication with the Firebase 3.0 SDK and Auth0 Integration', it is stated that:
You can even have Firebase communicate with Webtask!
Now I can imagine the (web)client triggering a Firebase operation and subsequently a Webtask, but not the other way around. Or am I missing something?
Firebase can run as a serverless app, but it can also run on the server. You can even have Firebase communicate with Webtask! (sic!)
I think that paragraph is misleadingly phrased, perhaps it was just added at the last minute to spark interest. You can have a webtask communicate with Firebase, not the other way around. You don't "run Firebase" on your server either.
TL;DR: A client application may call a webtask with an HTTP request, and that task can read/write the database, but not in any other order.
Here's a quick and dirty reality check as of Nov. 2016:
The Realtime Database by itself does not provide you with a way of executing code. This includes responding to database changes and user requests, handling fan-in and fan-out operations, etc. There is no support for webhooks either.
Which means you have to provide your own execution environment for such logic on a custom server, or you can try to cram as much as possible into the client code. This is a pretty exhaustive topic by itself.
Webtasks are short-lived functions that respond to HTTP requests. Their lifecycle always starts with a request, so they are not fit for continuously watching the database for changes. But they are perfectly valid for handling requests coming in from your client application.
As you can store "secrets" for the webtasks, you can authenticate the task on an admin access level. This gives you the possibility to verify client tokens – which should be sent along with the request –; perform complex authorization and validation, and perform RTDB write operations you wouldn't trust the clients with.
Or trigger external services securely. The possibilities are close to endless.

Resources