'news feed' like db structure

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Geteburg
Forum Commoner
Posts: 25
Joined: Tue Aug 12, 2008 1:57 pm

'news feed' like db structure

Post by Geteburg »

Hey

I was just on Facebook website and for some reason i got interested in their "news feed" feature.
It got me thinking on how on earth do they do that. I know that they have HUGE hardware behind it
and use caching, but still.
Come to think about it now, you have other website that offer the same thing..

Let's say that they save actions into one table..

Came up with two options:

Option 1:
- Get a list of my friends
- Get a list of recent activities from actions table, activity matches my friend list

Option 2:
- Each time an action is made, make INSERT for each friend i have

Now, i would say that the second option would be faster, but still.. Imagine having 500
friends. That means 500 INSERTs.

Isn't there any better way of doing this?
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: 'news feed' like db structure

Post by Eran »

Actually, I think the first approach is the better one. Since it is more normalized, caching is easier since the same event isn't spread to 500 hundred different users (in the database). Facebook probably caches parts of the feed separately for specific time spans, invalidate a chunk at a time to allow a new chunk to enter from above and so forth.

Their feed system by the way is quite broken. I can't recall how many times I've seen past events resurface as if they happened just now, over and over. But it's a social network so no one cares ;)
Post Reply