Search code examples
firebasegoogle-cloud-platformgoogle-cloud-firestoregoogle-cloud-functionsfirebase-storage

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

  1. how to set my firestore and cloud function in Hongkong but my Firebase Storage is Singapore ?
  2. If I can set in two different regions like that, is there any additional cost for this ?

Solution

  • 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.