1

Firebase documentation says we can have up to 200k connection limit per database,
enter image description here

Because we can have several references of that database in the project, I couldn't clearly understand what counts as a connection?

struct DatabaseService { // class ?
   let db = Database.database()
   let ref = db.reference("/path")
   let child = db.reference().child("/path")
   // what is the difference between ref and child? If no difference why do we have both of them?
   let db2 = Database.database()
   let ref2 = db2.reference()
   // db and db2 counts as one connection or two ?
   func observeRef() {
      ref.observe(.value) { snap in print("called") }
   }
   func observeRef2() {
      ref2.observe(.value) { snap in print("called") }
   }
   func removeAllObservers() {
      ref.removeAllObservers() // will this also remove ref2.observe?
   }
}

Should we create one database service class share its reference across app as singleton or is it okay to create a that service as a struct and create it whenever you need across the app? Will having one instance or having structs affect our database connection count?

OguzYuksel
  • 88
  • 6

1 Answers1

2

The Firebase SDK takes care of that for you (simultaneus connections). With the "simultaneus" connections it's more about how many different users from different Apps can be connected to your database. You can read more about it here.

A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. Firebase imposes hard limits on the number of simultaneous connections to your app's database.

db and db2 counts as one connection or two ?

It will count as one.

The child syntax is more or less just a different syntax you can use to make your code better to read. Instead of reference('123/dq/123') you can do reference(123).child("dq").child(123). it's just writing/syntax taste.

Tarik Huber
  • 7,061
  • 2
  • 12
  • 18