Let me start right off the bat, saying that I know this is not the best solution. I know this is kludgy and hack feature. But that’s why I am here!
This question / work is building some discussion of Quora with Andrew Bosworth , creator of the Facebook news feed.
I am creating a news feed . It is built exclusively in PHP and MySQL .

MySQL
The relational model for the feed consists of two tables. One table functions as an activity log; In fact, it was called activity_log . Another table is newsfeed . These tables are almost identical.
The schema for the log is activity_log(uid INT(11), activity ENUM, activity_id INT(11), title TEXT, date TIMESTAMP)
... and the scheme for the feed newsfeed(uid INT(11), poster_uid INT(11), activity ENUM, activity_id INT(11), title TEXT, date TIMESTAMP) .
At any time, when a user does something related to a news channel, for example, by asking a question, he will be immediately registered in the activity log .
Creating News Feeds
Then every X minutes (after 5 minutes it will be changed to 15-30 minutes), I started the cron task , which runs the script below. This script goes through all the users in the database, finds all the actions for all users of this user, and then writes these Actions in the news feed.
Currently, the SQL that selects the activity (called ActivityLog::getUsersActivity() ) has the LIMIT 100 argument set for performance *. * Not that I know what I'm talking about.
<?php $user = new User(); $activityLog = new ActivityLog(); $friend = new Friend(); $newsFeed = new NewsFeed(); // Get all the users $usersArray = $user->getAllUsers(); foreach($usersArray as $userArray) { $uid = $userArray['uid']; // Get the user friends $friendsJSON = $friend->getFriends($uid); $friendsArray = json_decode($friendsJSON, true); // Get the activity of each friend foreach($friendsArray as $friendArray) { $array = $activityLog->getUsersActivity($friendArray['fid2']); // Only write if the user has activity if(!empty($array)) { // Add each piece of activity to the news feed foreach($array as $news) { $newsFeed->addNews($uid, $friendArray['fid2'], $news['activity'], $news['activity_id'], $news['title'], $news['time']); } } } }
News Display
In the client code, when you select the user feed, I do something like:
$feedArray = $newsFeed->getUsersFeedWithLimitAndOffset($uid, 25, 0); foreach($feedArray as $feedItem) {
News improvement
Now forgive my limited understanding of the best news channel development practices, but I understand the approach that I use to be a limited version of what is called fan-out when recording , limited in the sense that I am doing cron work as an intermediate step instead of to write directly to user news feeds. But this is very different from the pull model, in the sense that the user's news feed is not compiled at boot time, but rather on a regular basis.
This is a big question, which probably deserves a lot of back and forth, but I think it can serve as a touchstone for many important conversations that new developers like me should have. I'm just trying to figure out what I'm doing wrong, how I can improve, or how I should even start from scratch and try a different approach.
Another thing that deceives me in this model is that it works on the basis of relevance, not relevance. If anyone can suggest how this can be improved to work with relevance, I would be all ears. I use the Directed Edge API to generate recommendations, but it seems like something like a news channel, the recommendations will not work (since there was nothing before!).