0

In a Firebase social-media-esque app, here is how I'm storing groups along with its members:

Here, I have a reciprocating relationship in terms of memberships of groups. A group knows all of the users that are a part of it in group-users and vise-versa—a user knows all of the groups it's in via user-groups. The reason I thought to do this is it seems to be quick for a user to access all of its groups, and likewise it seems to be quick for a group to access all of its users. However, having this reciprocating data is costly in terms of space. My other option would be to keep just the user-groups node, and to retrieve all the members of a single group I would need to query that node by group ID. This option seems slower but would take less space in the database. Which option is more advised? Thanks.

Community
  • 1
  • 1
Archie Gertsman
  • 1,601
  • 2
  • 17
  • 45

1 Answers1

0

The best data model always depends on the use-cases of your app. If you need access to both the groups-for-a-user and the users-for-a-group, the cheapest way to do so is to store both.

See:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807