firebasefirebase-realtime-database

Multiple Firebase projects in one app


I'm building an app that has an arbitrary amount of 'micro-communities' on it. Currently a user can only belong to one, so when they initially sign up, they enter a secret code which associates them with the relevant community.

Is it wise to separate these 'micro-communities' (which are owned by future clients playing for a space on the app) into separate Firebase projects or keep all the data together?


Solution

  • I recommend you to keep all the communities together. First, because I'm not really sure that you can use multiple Firebase Projects in the same app.

    I suggest you to store this "communities" as items in your database with all their current info. For example:

    {
        "Communities":{
                "CommunityKey1":{
                    "communityName":
                    "createdDate":
                    ....
                }
                "CommunityKey2":{
                    "communityName":
                    "createdDate":
                    ....
                }
                "CommunityKey3":{
                    "communityName":
                    "createdDate":
                    ....
                }
                ....
            }
    }
    

    And when you add your users to your database, just add them an associated field "currentCommunity" or something like that where you store the associated communityID for that user. Then, when you want to filter the users for one community just use:

    FirebaseDatabase.getInstance().getReference().child("users").child("currentCommunity");
    

    You can filter else more using .equalTo("CommunityID") at the end of that query. I'm not an expert in Firebase, but I'm doing an app with a similar kind of user filtering(using groups instead of communities and they can belong to more than one), and the best way to do this was using this model.