7.17. The Graphity activity stream model

7.17.1. Find Activity Streams in a network without scaling penalty

7.17.1. Find Activity Streams in a network without scaling penalty

This is an approach for scaling the retrieval of activity streams in a friend graph put forward by Rene Pickard as Graphity. In short, a linked list is created for every persons friends in the order that the last activities of these friends have occured. When new activities occur for a friend, all the ordered friend lists that this friend is part of are reordered, transfering computing load to the time of new event updates instead of activity stream reads.

[Tip]Tip

This approach of course makes excessive use of relationship types. Right now now the maximum amount of relationship types in Neo4j is 65.000 which needs to be taken into consideration when designing a production system with this approach.

To find the activity stream for a person, just follow the linked list of the friend list, and retrieve the needed amount of activities form the respective activity list of the friends.

Query. 

START me=node:node_auto_index(name = "Jane")
MATCH p=me-[:jane_knows*]->friend, friend-[:has]->status
RETURN me.name, friend.name, status.name, length(p)
ORDER BY length(p)

The activity stream for Jane.

Result

me.namefriend.namestatus.namelength(p)
3 rows
0 ms

"Jane"

"Bill"

"Bill_s1"

1

"Jane"

"Joe"

"Joe_s1"

2

"Jane"

"Bob"

"Bob_s1"

3


Try this query live. (1) {"name":"Bill"} (2) {"name":"Ted_s1"} (3) {"name":"Bill_s1"} (4) {"name":"Ted_s2"} (5) {"name":"Bill_s2"} (6) {"name":"Jane"} (7) {"name":"Joe_s1"} (8) {"name":"Bob"} (9) {"name":"Ted"} (10) {"name":"Joe_s2"} (11) {"name":"Bob_s1"} (12) {"name":"Joe"} (1)-[:has]->(3) {} (1)-[:jane_knows]->(12) {} (2)-[:next]->(4) {} (3)-[:next]->(5) {} (6)-[:jane_knows]->(1) {} (7)-[:next]->(10) {} (8)-[:bob_knows]->(9) {} (8)-[:has]->(11) {} (9)-[:has]->(2) {} (9)-[:bob_knows]->(1) {} (12)-[:has]->(7) {} (12)-[:jane_knows]->(8) {} START me=node:node_auto_index(name = "Jane") MATCH p=me-[:jane_knows*]->friend, friend-[:has]->status RETURN me.name, friend.name, status.name, length(p) ORDER BY length(p)

Figure 7.21. Graph