database design - Graph-based News Feed & Activity Log -


for few days, i've been working on developing newsfeed using neo4j graph database , toying around various ways of including activity log (similar facebook) keep track of every user action.

for example, user1 sends friend request user2 (which translate in cypher):

match     (me:user {username: 'john.snow@gmail.com'}),      (friend:user {username: 'arya.stark@gmail.com'})       not (me)-[:friendship_update]-(:friendshipstatus)-[:friendship_update]-(friend)  create     (me)-[:friendship_update]-(friendshipstatus:friendshipstatus {status: 0})-[:friendship_update]->(friend)  return     me,     friendshipstatus,     friend 

pretty basic stuff far, create 2 relationships , 1 node contains information regarding friendship.

retrieving both outgoing , incoming events pretty simple:

match     (me:user {username: 'john.snow@gmail.com'})-[actionname]->(actiondata)-[]->(friend:user)  return     me,     type(actionname) actionname,     actiondata,     friend  union match     (me:user)<-[actionname]-(actiondata)<-[]-(friend:user)  return     me,     type(actionname) actionname,     actiondata,     friend 

but, let's user2 declines user1 friend request, end deleting entire relationship between them. no problem... simple notification panel (like "you have 1 friend request", other cancels friend request, "oups, no friend requests"). so, no history.

like said, i'm planning facebook activity log.

> liked [user]'s*link user* [photo]*link photo* @ [time]. > [user]*link user* declined friend request @ [time]. > sent [user]*link user* friend request @ [time] 

i've toyed various ways of doing this, including linked lists, down day. days contain events user performed or has been exposed in particular day (when creating event, pushed friend timeline - see second code block) , keeping direct relationships between user (friendship updates, likes, etc) speed don't have search thru day nodes.

edit: forgot mention why didn't stick particular design.

the problem there no similarity between actions (for example "like" directed "post" while "friendship request" directed "user"), made me end multiple, unwanted joins.

what database design keep track of these actions, if deleted?

thank in advance.

a useful event log must not delete log entries , must reliably return entries original data. essentially, log entries static data must never change, once created.

  1. probably best solution maintain separate "log db" (perhaps not graph db) of log entries events. keep "live data" db simpler, , logging mechanism simpler.
  2. if wanted use same neo4j db log entries, keep in separate "log subgraph" disjoint "live data subgraph" (i.e., no shared nodes, , no relationships between "log nodes" , "live nodes" -- although log properties can contain identifying info live data). reason has disjoint because live data can change @ time (e.g., nodes/relationships can deleted, properties can change, etc.), log entry must still able return data state applied @ time entry created. approach may more effort worth, though.

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -