Why should Firebase cloud functions triggered by Realtime database be located in us-central1 region - firebase

Firebase cloud functions documentation says that background functions triggered by Realtime database should always be located in us-central1 region. It doesn't explain why, though.
Is it also applicable to the cases when Realtime database is located in Europe or Australia? Or is it ok to put this type of functions closer to Realtime database location?

firebaser here
tl;dr: that doc page is outdated, so I filed a request to update it.
You should should select the Cloud Function region closest to where your Realtime Database is hosted to avoid cross-region traffic.
https://firebase.google.com/docs/projects/locations#rtdb-locations
Realtime Database was only available in us-central1 for a long time, but is available in europe-west1 and asia-southeast1 now too. We probably forgot to update the documentation at that point, so... thanks for catching it.

Related

How to get the location/region of an Datastore instance

To call the Datastore.export() API I need to provide a GCS bucket name in the same region as the Datastore I'm exporting.
I checked with node.js' #google-cloud/datastore Datastore instances seem to have no .location property or something similar. Also, the Google provided Datastore libraries in other languages seem to lack this functionality.
With other Google APIs you usually have a way to get the Location of the resource. E.g. in GCS: Storage().bucket('mybucket').getMetadata().location -> 'EU'.
How to view Google Cloud Datastore Region shows to get this information in a manual way, but I'm after programmatic access.
Firestore has a database get method (in preview as of 2021-12-23), that you can use to lookup the location of your database. This API will also tell you the mode of your database (Firestore native vs Datastore mode).

Firebase realtime database and Cloud Functions locations and speed

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.

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.

Cloud Firestore & Cloud Firestore for Firebase

What is the difference between Cloud Firestore and Cloud Firestore for Firebase?
Here's a thread asking the same, but someone, please enlighten me.
https://www.reddit.com/r/googlecloud/comments/bb9n46/what_is_the_difference_between_the_cloud/
Is it the same? If not, which one to use?
The link you have shared is talking about the differences between quickstarts, Firestore as a service within GCP and Firestore as a service within Firebase. There also two different consoles for that. Both doing the same thing.
Please note that Cloud Firestore as a service is available with, or without Firebase SDKs.
Is it the same?
The difference that I see between them is that in Firebase console you can set the security rules and you access other services like IAM, BigQuery, more easily.
If not, which one to use?
If you are used to work in a Google Cloud Platform environment, use the Cloud console, otherwise use the Firebase console. So it depends on whatever your preference is.
For more informations, I recommend you read Doug Stevenson's post on medium.com regarding the same topic:
https://medium.com/google-developers/firebase-google-cloud-whats-different-with-cloud-firestore-40f1fc3e6d1e

Where to check for Firebase Realtime Database Location (US, EU, or Asia)

I'm a developer in Australia and and I'm using the Firebase Realtime database for a project on Android and iOS.
Customers are complaining about lag and delays, especially when logging-in, and I'm trying to find out if any Firebase processes are by default on US servers, but can be moved to Asia to improve performance.
When I check my Google Cloud Console, the default Storage Bucket is set up as the US, but I cannot find any information about the Firebase Realtime Database.
Update: as of late 2020 Firebase Realtime Database instances can be in different locations. You can find the location of your database as the bottom of the data viewer in the Firebase console, as also shown in the screenshot in Jürgen's answer.
All Firebase Databases are hosted in the central US. There is no way to change this at the moment.
When you open the RTDB console you can see it at the bottom as indicated in the image. This feature is currently in a beta state. https://firebase.google.com/docs/projects/locations?authuser=0#rtdb-locations

Resources