1

I'm new to storing and retrieving large amounts of data from a database. I have an iOS app that stores data with Firebase and everything is working fine, but I'm worried that once there's more and more data, performance will suffer.

For example, when creating a profile, the user must choose a username that has not already been taken. In order to do this, I retrieve all of the existing usernames and check if the new username is already there. My question then is how can I test what will happen if there are thousands or even millions of existing usernames?

Thanks in advance.

AL.
  • 36,815
  • 10
  • 142
  • 281
Adam Zarn
  • 1,868
  • 1
  • 16
  • 42
  • 1
    There's no need to collect all of the user data to see if a username exists - do a query for it. If you follow typical design patterns such as denormalize data, leverage queries to find specific data but don't overuse them, duplicate data when needed etc, you'll find Firebase can handle hundreds of thousands (millions) of pieces of data with no degradation in performance. *if you have millions of usernames... cheers to that! – Jay Feb 23 '17 at 22:42
  • The key here is in Jay's first sentence: storing data is infinitely scalable. Accessing a single node in that data is almost as scalable. But querying a million nodes to check if one value exists in there is not. So the solution is to pick a data structure that doesn't require querying. Also see: http://stackoverflow.com/questions/39712833/firebase-performance-how-many-children-per-node/39713060#39713060 – Frank van Puffelen Feb 24 '17 at 03:40

1 Answers1

2
Root
    Profiles
        [username1]
             ...
        [username2]
             ...
        [username3]
             ...

    let ref = FIRDatabase.database().reference().child("Profiles").child("\(username)")
    ref.observeSingleEvent(of: .value, with: {snapshot in
            if snapshot.exists() {
                print("user exists")
            } else {
                print("user not exists")
            }
        })
Peter Cheng
  • 399
  • 1
  • 7