Originally published at: http://www.sitepoint.com/efficient-user-timelines-php-application-neo4j/
Any social application application you encounter nowadays offers you a timeline, showing statuses of your friends or followers generally in a descending order of time.
Implementing such a feature has never been easy with common SQL or NoSQL databases.
Complexity of queries, performance impacts increasing with the number of friends/followers and difficulties to evolve your social model are points that graph databases are eliminating.
In this tutorial, we’re going to extend the demo application used by the two introduction articles about Neo4j and PHP, respectively :
The application is built on Silex and has users following other users. The goal throughout this article will be to model the feature of feeds efficiently in order to retrieve the last two feeds of the people you follow and order them by time.
You’ll discover a particular modeling technique called Linked list and some advanced queries with Cypher.
The source code for this article can be found in its own Github repository.
Modeling a timeline in a graph database
People who are used to other database modeling techniques tend to relate each feed to the user. A feed would have a timestamp property and the order of the feeds will be done against this property.
Here is a simple representation :