1

I am trying to make a chat application based on suggestions in the Firebase documentation about denormalizing.

I have a list of chat rooms the user is part of in the user node like this:

{
  "user": {
    "chat_ids": {
      "room_1_id": true,
      "room_2_id": true
    }
  }
}

and chat node as:

{
  "room_1_id": {
    "last_posted": "date"
  },
  "room_2_id": {
    "last_posted": "date"
  }
}

The chat node has rules that which prevent members who aren't part of a room to read that node. I am getting the list of chat ids from the user node and then getting details of each chat and attaching listeners to each chat child to detect change in them.

My question is in case a user is part of 20+ chat rooms, there will be 20 listeners, so will that cause performance issues? If so is there any alternate way to solve this issue?

user3686910
  • 13
  • 1
  • 4
  • Listeners are only as expensive as the amount of data they listen to. See these answers: [1](http://stackoverflow.com/questions/28330358/firebase-multiple-child-listenres), [2](http://stackoverflow.com/questions/37635733/inexpensive-firebase-listeners). A bigger question is why you would want to listen to 20 chat rooms? Are you going to be display all those rooms on the screen? In general a mobile app should only download/synchronize data that it displays and 20 rooms sounds like a lot of chat messages. Or is it only metadata? – Frank van Puffelen Sep 02 '16 at 13:59
  • Thanks for the reference and yes all the chat rooms will be displayed on the screen, but it will only contain metadata like last posted date. I am afraid of the memory usage, since i am attaching listener to each chat node. – user3686910 Sep 02 '16 at 17:08
  • The links tell you to not care, when it comes to a few dozen listeners. That said: consider modeling your data in a way that makes it cheaper to query. See this article on [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/). – Frank van Puffelen Sep 02 '16 at 20:26

0 Answers0