I build a social network with Neo4j, it includes:
Node labels: User
, Post
, Comment
, Page
, Group
Relationships: LIKE
, WRITE
, HAS
, JOIN
, FOLLOW
,...
It is like Facebook.
example: A user
follow B user
: when B
have a action such as like post, comment, follow another user, follow page, join group, etc. so that action will be sent to A
. Similar, C
, D
, E
users that follow B
will receive the same notification.
I don't know how to design the data model for this problem and I have some solutions:
Notification
nodes for every user. If a action is executed, create n
notification for n
follower. Benefit: we can check that this user have seen notification, right? But, number of nodes quickly increase, power of n
.I believe that the best approach is the option 1. As you said, you will be able to know if the follower has read or not the notification. About the number of notification nodes by follower: this problem is called "supernodes" or "dense nodes" - nodes that have too many connections.
The book Learning Neo4j (by Rik Van Bruggen, available for download in the Neo4j's web site) talk about "Dense node" or "Supernode" and says:
"[supernodes] becomes a real problem for graph traversals because the graph database management system will have to evaluate all of the connected relationships to that node in order to determine what the next step will be in the graph traversal."
The book proposes a solution that consists in add meta nodes between the follower and the notification (in your case). This meta node should got at most a hundred of connections. If the current meta node reaches 100 connections a new meta node must be created and added to the hierarchy, according to the example of figure, showing a example with popular artists and your fans:
I think you do not worry about it right now. If in the future your followers node becomes a problem then you will be able to refactor your database schema. But at now keep things simple!
In the series of posts called "Building a Twitter clone with Neo4j" Max de Marzi describes the process of building the model. Maybe it can help you to make best decisions about your model!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With