How to deploy Firebase functions and other services in multiple locations? - firebase

Is it possible to deploy Firebase services in multiple locations?
Reading up on Select locations for your project it seems like it's not possible to deploy Firebase globally.
The current multi-region locations are eur3 and nam5 which cover Europe and the US in multiple locations.
What if there is a need to cover Europe and US simultaneously? Did anyone come across the same issue, if so, I would appreciate if you'd share your experience.
EDIT:
We are using Functions and Firestore services. If we deploy functions globally we will also have to have Firestore in two projects or use the default GCP resource location for Firestore with functions in multiple regions.

Related

How to run different cloud functions for seperate apps in the same Firebase project?

For example, if I wanted to use the functions.auth.user().onUserCreate() trigger, is there any way to make it trigger different functions for different apps that are all in the same Firebase project? Is the only way to fix this to create separate Firebase projects for each app? The issue with that is that I need them to access the same database.
It's not possible to know in a Cloud Functions trigger which app a user used when they created their account. Firebase Auth accounts don't have a sense of "ownership" with respect to multiple apps per project. All apps in a project share the same users with the same permissions.
What you can do instead is have each app write something unique in your database after the account was created, then use that to determine what that user should do later on. Either that, or use different projects if your apps don't actually need to share the same set of users.
The only possibility that I think that might help you is organizing your Cloud Functions in different files, which will be then loaded per project. So, for example, in your Project Alpha, it will run the Cloud Functions from the foo.js file, while in the Project Beta, it will run the functions from the bar.js and the same logic for other projects and Cloud Functions.
This way, even though all users are sharing the same database, it will trigger the function based in the file that you requiring in your application. You can check for tips in organizing your Cloud Functions in multiple files and calling them individually, in this official documentation here:
Organize Functions
I believe this way might work for you, so, I would recommend you to check the documentation and give it a try splitting the functions in multiple files and calling each specific files, on their specific applications only.
Let me know if the information helped you!

Multiple firebase environments in different regions

I am building a web application and need a dev instance and a prod instance. In the past I've always made two separate firebase projects (project-name-dev and project-name-prod) and used aliases to deploy to each environment.
I now have a need to host the same project in two different regions (US data needs to live in US, Canada data needs to live in Canada). I still need a dev and prod instance. My current thought is to create two new projects totaling 4 separate firebase backends that all use the same frontend
project-name-us-dev
project-name-us-prod
project-name-ca-dev
project-name-ca-prod
The front end code is using Vue.js. (not sure if that's relevant or not)
Is there a simpler way of managing this project?
Thanks!
Since you tagged this question google-cloud-firestore, I'll assume that you are mostly referring to the location of the data in Firestore. I suggest reading this if you haven't already. Once you've chosen a region for Firestore, that project is locked into that location for the rest of its life, in addition to its default storage bucket as well as GAE. Since you can't have two Firestore instances in the same project, and you have to choose a location for Firestore in the project, it stands to reason that there isn't any easier way to manage your projects than what you're doing now.

Multiple Cloud Firestore for single project

I have a project with 2 schemes, one for development and other for production. I am also using firebase, hence I created 2 projects and injected two google plists under different names in the project. I also need to access google cloud platform. I cannot change/modify cloud functions without affecting my production application. Is there a way where I can have two Firestore for single project so that editing/ changing functions in on won't affect other?
It's not possible to have multiple Firestore instances per project.
It's not entirely clear to me what the problem is with your use of Cloud Functions, but the functions running in each projects should automatically use the Firestore instance for the project that they've been deployed to. If you need to access a different Firestore instance, then you will need to deploy some configuration for your functions so they can initialize an instance of the Cloud SDK that you're using to read and write Firestore

Access control on Firebase databases

We are having different environments for one of our solution (test, preprod, prod). We've created different Firebase databases as part of single project on Firebase console. We want to have access control implemented to these databases depending on users or groups e.g. prod Firebase database will be accessible to only few users where as other environment's (test and preprod) Firebase database will be accessible to most of the users.
Are we implementing it correctly? If yes, would it be possible to configure Firebase project to have this kind of setup.
This is not the recommended way to implement different development environments. The only recommended way to separate environments is to create different Firebase projects for each one. This ensures that they each have completely isolated data, users, security rules, and so on. Adding multiple databases to the same project isn't true isolation, and could lead to problems later on.

Firebase Functions: is it OK to divide functions to multiple projects

This is in relation to the question here: Google Cloud / Firebase Functions, handling dependencies per function
So, to manage dependencies better, is it allowed to divide the functions to as many projects as we see fit?
This would create one "master" project, that contains the data in database and storage + the projects that are otherwise empty, but contain only certain functions.
Thins of the following projects: My Awesome App, My Awesome App Stats Api, My Awesome App Admin Api etc.
It depends on what kinds of functions you're writing.
If you want to write database triggers, they have to be in the same project as the database that's receiving the writes. You can't have a second project respond to writes from the database in the first project.
If you want to write HTTP triggers, you can init the admin SDK to point to different projects for querying and such.
I don't particularly see any need to "shard" your functions like this in a production environment. Cloud Functions will scale your functions as needed to handle the load, and having different functions in different projects shouldn't make a difference in that respect.

Resources