Ashish Jha
Ashish Jha

Reputation: 183

Multiple instances of Firebase

I am developing an Android application. Actually my app is for Societies/Apartments use. And I am using Firebase to store all the data of the app. I have a Firebase database and I want to assign one instance of Database to one society. Like Society A will have one instance of database. Society B will have another instance of same Database. And so on. And master database will have the link of all its instances of database. How can I achieve it? I also wanted to know How many instances of a database can we create in Firebase for one project?

Upvotes: 0

Views: 2104

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599001

firebaser here

The ability to have multiple instances of the Realtime Database is to allow it to scale beyond the capabilities of a single database. This is known as sharding, as key to this approach is dividing your entire user-base into separate shards, where the shards have minimal interaction with each other.

You should consider however if you really need a separate shard for each society/apartment. I recommend studying When to shard your data carefully and see if your usage is really going to go beyond the scalability abilities of a realtime database instance. While technically sharding sounds very possible with your scenario, using shards complicates matters significantly, so you should only use this when it is actually needed.

E.g. you could easily start of by segmenting the data for the societies/apartments into separate branches in a single database instance:

/apt1
  users
  groups
  places
/apt2
  users
  groups
  places
/apt3
  users
  groups
  places

Then if you ever reach the need to shard, you can move some of these apartments into another database instance, and use a master database (or an implicit key mapping, which typically scales better) to tie users/apartments to a database instance.

There is no documented limit on the number of shards. Each database instance is quite literally that: a separate database with its own URL, (possibly) on different infrastructure, etc. There probably is a physical limit to how many instances can be created, but I would again refer back to the previous paragraph: if you find yourself creating hundreds of shards, you're probably using them for more than is needed.

Upvotes: 2

Related Questions