0
votes

I design a neo4j db, this db has two label User and Group. Each user can be a member or admin in group. I need to save creator of group too. So I have 3 possible role for a user in a group.

For now I save user roles in a list property called type on relation called MEMBER_OF_GROUP. A member has MEMBER in this list, and this also work for creator and admin, so a user that is creator of group, admin and member of group has MEMBER,ADMIN,CREATOR in type list on the relation to group, like example image bellow. Template of first design In this design it's harder to find role of a user in group, because I first need to check if relationship is exist and then check if that role is in type property.

I can redesign db and add 3 relation for every role a relationMEMBER_IN_GROUP, CREATOR_OF_GROUP, ADMIN_OF_GROUP. Which design is better? Have multi relationship between two nodes or add one node and a property to save roles? may multi relation cause any problem? is any better design for this problem?

1

1 Answers

0
votes

If you're going to be constantly looking for the specific role I see more benefits on having multiple relationships. It's so much faster to follow a rel than iterating over an array property, properties are physically stored in a different location than relationships and nodes so Neo4j needs to do some extra effort just to access it.

As a general advice, when it comes to modeling it's good to look at how you will be querying the database and the performance effects on how you will write them. If you want detailed information on how Neo4j stores data search for their "native graph" technology concepts. https://neo4j.com/blog/native-vs-non-native-graph-technology/

You can find more tips on modeling graph databases with Neo4j on Chapter 3 of this book: https://neo4j.com/graph-databases-book/