Firebase realtime database and Cloud Functions locations and speed - firebase

I have a Firebase realtime database project that was originally created on the central1 server (USA).
The problem is that the applications using this database and the Cloud Functions related are all used in Europe (mainly France). Someone in the same situation changed the server to "europe-west1" and noticed a big improvement in term of speed for the Cloud Functions.
So I have several questions : will it really affect the speed? And also, do I have to change both the database and the Cloud Functions locations to make it work smoothly?
It is easy to change the Cloud Functions locations but it seems not possible to change the location of a realtime database once it is created.
I am afraid having a database located in USA and the Cloud Functions running from Europe would be even worse...

According to the Cloud Functions documentation the region recommended to deploy the Cloud Function if they are triggered by or uses a Realtime Database is always US-Central1.
An alternative to provide a better experience for the non-us users could be implementing a small function in the EU zone for all the non database related job that later connects to the Cloud Functions that does all the job related to the database.

Related

Unknown buckets stored in my Google Cloud Platform storage

I have a bunch of buckets in my Google Cloud Platform storage, and I'm not sure where they come from as I have never stored anything in the storage in the past.
What are these buckets for?
Cloud Storage is used as backend of several product. When you build a GCF (Cloud Functions), an APp Engine or you store a Container, the data behind the container created (for Cloud Functions and App Engine) need to reside somewhere. And it's on this special buckets.
You find the artifact buckets EU and US, you should have container in gcr.io and eu.gcr.io, you should have an app engine in US, and deployed at least 2 function, one in europe-west2 and one in us-central1.
Main problem today (and there is side discussion with Google on this): no automatic cleaning is performed on these buckets.

can I set my firebase storage in different region from my Firestore and cloud function?

most of my users will be in Indonesia. I am using Firestore, Cloud Function and Firebase storage in my project. currently I am in development phase and all my data is temporarily stored in us-central 1.
when fetching data from firestore or when I trigger the cloud function, the speed of operation is still acceptable around 1-3s (my data in us-central 1 and I am in Indonesia).
but when fetching image data from Firebase storage, it feels so slow due to high latency. so that is why I want to recreate my project and choose the region as near as possible from Indonesia
but if I see from the table in here: https://cloud.google.com/about/locations#asia-pacific
the nearest cloud storage for firebase from Indonesia is in Singapore, but unfortunately firestore and cloud functions are not available yet in Singapore,
the nearest firestore and cloud function available region from Indonesia are in Hongkong.
so my questions are
how to set my firestore and cloud function in Hongkong but my Firebase Storage is Singapore ?
If I can set in two different regions like that, is there any additional cost for this ?
How to set my Firestore and Cloud Function in Hongkong but my Firebase Storage is Singapore ?
As explained in the documentation:
Before you use Cloud Firestore, you must choose a location for your
database... This location setting is
your project's default Google Cloud Platform (GCP) resource location.
At the time of writing, this Cloud Firestore location is an immutable choices, i.e. it is not changeable (Creating a new project is the only way to change it).
For Cloud Storage, "your default GCP resource location is used for GCP services in your project that require a location setting, specifically, your default Cloud Storage bucket". However, with Cloud Storage, you have the possibility to create new buckets in other locations, if you are under the Blaze pricing plan.
You already got an answer, here, on how to reference to a specific bucket :-)
For Cloud Functions, you should refer to this documentation. You will read that "by default, functions run in the us-central1 region" but that it's quite easy to change the location of a Cloud Function by setting the region parameter in the function definition.
If I can set in two different regions like that, is there any additional cost for this?
Yes, you will have extra cost if your Cloud Function (which is in asia-east2 i.e. Hong Kong) interacts with your Cloud Storage (e.g. creates a file in Storage) which is in asia-southeast1, i.e. Singapore. More details in the documentation, here and here.

Can Firebase Cloud Functions Use an In-Memory Cache?

I am using Firebase cloud functions for a project, and some of those functions fetch data from a firebase database.
I'd like to speed up some of these queries by leveraging a LRU cache, but it's not clear whether this is possible with Firebase cloud functions.
Does anyone know if the Firebase cloud functions have access to any kind of cache / semi-persistent memory access? Any help others can offer on this question would be hugely helpful!
If you want to share any sort of persistent data between function invocations, you will have to use another product, and code your function to use that. Cloud Functions themselves only have immedaite access to the memory on the server instance that's running a particular invocation, and there could be many server instances all running functions at the same time.
If you're OK with maintaining a small local cache in memory on each instance, that's fine. But you will have problem with this if you allow the cache to get so large that a function can't do its work with more limited memory. You should also expect the cache to get reset whenever a server instances get deallocated, which happens outside of your control.
Since you're working in Google Cloud, consider using a product such as Memorystore to implement your cache.

Can I read data from realtime data base across cloud functions in react native

I want to read and write data in database real time across cloud functions but I don't know if this is possible, also I don't know if this is good practice or if is better make this through with SDK database realtime
I learning firebase and react native, I am new learning these topics.
From the docs:
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.
Cloud Functions runs Node v.6.11.5, so we recommend that you develop locally with this version.
You are able to use realtime database trigggers like onCreate(), onWrite(). Also you are able to use set() to send data to the realtime database.
https://firebase.google.com/docs/functions/
https://firebase.google.com/docs/functions/database-events

How do I use Cloud DataStore or Cloud SQL from Cloud Functions for Firebase?

I'm building a Firebase app, and plan to use the real-time database when I need real-time updates. However, most of the application data is more traditional.
Now that Functions is a thing, how do I also leverage either DataStore or CloudSQL? Can anyone point me to specific documentation or examples how to read/write with either of those services from a function?
Neither Cloud Datastore nor Cloud SQL support Cloud Functions yet, which means you aren't yet able to trigger Cloud Functions based on their events the way you can with the Firebase Realtime Database.
Fortunately, once a Cloud Function has been triggered (for example via HTTP), you can still read and write from Datastore and SQL as you would from any other Node.js code. Here is documentation for Cloud Datastore, and here it is for Cloud SQL.
Finally, if you're adventurous and might like to provide early feedback on upcoming integrations like Datastore, fill out this form!

Resources