Data model for social media notification?

I am building a social network with Neo4j, it includes:

Node Tags: User

, Post

, Comment

, Page

,Group

Relationship: LIKE

, WRITE

, HAS

, JOIN

, FOLLOW

, ...

It's like Facebook.

example: A user

follow B user

: when B

has an action such as post, comment, follow another user, follow a page, group of unions, etc. so that the action is posted to A

. Similarly, C

, D

, E

users who follow B

, will receive the same notification.

I don't know how to create a data model for this problem and I have some solutions:

  • create Notification

    nodes for each user. If the action is completed, create a notification n

    for the n

    follower. Benefit: We can verify that this user saw the notification, right? But the number of nodes is rapidly increasing, the power n

    .
  • create a request for each API call notification (for the client application), this request only receives a list of user actions at a specific time (24 hours or 2, 3 days). But Followers do not check this notification or for now, and this request can make the server slow.
  • create a node with a limited number, for example 20, 30 nodes per user.
  • Create unlimited nodes (including expiration time) for 24 hours, and these nodes have an expiration time property> 24 hours will be deleted (expiration time can be 2, 3 days). Who can help me solve this problem? Should I choose which solution or new way?
+3


source to share


1 answer


I believe the best approach is option 1. As you said, you will be able to know if the follower has read the notification or not. On the number of notification nodes by witnesses: This problem is called "supernodes" or "dense nodes" - nodes that have too many connections.

Learning Neo4j (by Rik Van Bruggen, available for download from the Neo4j website ) talks about the "Dense node" or "Supernode" and says:

"[supernodes] become a real problem for graph traversals, because the database management system will have to evaluate all connected relationships to that node to determine what the next step is to traverse the graph."

The book proposes a solution to add meta nodes between the follower and the notification (in your case). This meta node should have at most one hundred connections. If the current meta node reaches 100 connections, according to the example picture a new meta node should be created and added to the hierarchy showing an example with popular artists and your fans:



Dense node

I guess you are not worried about this right now. If your node proponents become a problem in the future, you should be able to refactor your database schema. But now everything is simple!

In a series of posts titled "Creating a Twitter Clone with Neo4j", Max de Marzi describes the process of building a model. Perhaps this will help you make the best decisions about your model!

+2


source







All Articles