Jorge Montalvão
Jorge Montalvão

Reputation: 135

Move Firebase project to another region

I am using Firebase for a long time (since 2018) and loving it. In that time there was not Location southamerica-east1 (São Paulo). Now I would like to store the project (web app, cloud function, and database) in southamerica to reduce cost and make it near to my end-users (also based in Brazil).

My project storage detail

I have source control, all environment parameters values stored in Custom Environment Variables. The application works fine when no data is found. No concerns with backup data. No problem about downtime. This is not a critical app.

Anyway, I can't delete the application because I already have some users logged in there and IoT devices sending data through PubSub.

  1. How can I rebuild my Firebase/Firestore/Web application/Function from the ground up, and make sure the new location is southamerica? If possible, I need to keep user and passwords, and web

Looking forward, (I don't think moving the bucked location would be the best solution here) but based on this page Select locations for your project I can't update the location, but since it is based on bucked location, if it doesn't break the project, I will use Google Cloud Transfer Page to Moving and renaming buckets

  1. May is it a better solution than rebuild the app (Firebase/Firestore/Web application/Function)?
  2. May I break my Firestore database or cloud function or web app?
  3. May I lost my project domain or any other related URL parameter like authDomain, databaseURL, storageBucket?
  4. May I need to update some web app parameter after the change?

Upvotes: 4

Views: 3084

Answers (2)

Jan Hernandez
Jan Hernandez

Reputation: 4640

Based in your information, the main issue is Firestore because other products are globally balanced like Cloud IoT Core and Hosting (these can't be configured on a specific region)

Other products like Functions can be redeployed with the same code and name into another region.

I think that you can create another project only to move the database to the new region and configure all Cloud resources to reach the new located database.

As a caveat, you need to add another domain/subdomain and create new credentials to work with the new project; this step can´t be skipped because it is required for authentication.

On the application side you can add the access to the new database

In case you need assistance during your migration you can start a case with GCP/Firestore support.

This is a hard pill to swallow, but maybe the costs and the time to migrate to another region will be higher than keeping your application as is working today.

Upvotes: 2

Kato
Kato

Reputation: 40582

They cannot be moved at present and migrating data is a manual process. Difficulty varies by product.

General guidance

  1. Do not delete the old project before fully migrated.

Hosting

This migration is nearly trivial, with the understanding that there is likely a minor service interruption while moving custom domains.

  1. Deploy to the new site
  2. CNAME your custom domain to the new site (myproject.firebaseapp.com)
  3. Delete custom domain from old site
  4. Add custom domain to new site

Cloud Functions

This migration is trivial.

  1. Create a local directory for your new project
  2. Run firebase init and set up project normally (enable Functions)
  3. Copy your Functions code into the new project's functions/ directory
  4. Deploy to the new project

Database

This migration is tricky, difficult, and highly specific to your use case and tolerance for downtime. What follows is a general template to adapt.

Reference docs for import/export: Firestore import/export, Realtime Database backups

  1. In the old project:
    1. Lock the database using security rules to prevent changes
    2. Export existing database
  2. In the new project:
    1. Import the database backup
    2. You probably need to migrate existing users (see account export/import) as well so user ids stored in your DB will still reference the correct accounts
  3. Point existing apps to the new project

If downtime is not an option, or if you'll be deploying a new mobile app version and need time for changes to propagate, then you'll need to set up a dual write model:

  1. Dual sync: Create a Cloud Function on both the new and old database that duplicate all create/update/delete operations on the respective partner endpoint.
  2. Sync pre-existing data: Perform the export/import process as above on all data created before the dual sync was implemented, excluding the step to lock the old database
  3. Shut down your old mobile app version (once enough accounts have migrated)
  4. Shut down the dual sync Functions and turn down the old site

Upvotes: 4

Related Questions