Modeling facebook-style news feed

216 views
Skip to first unread message

Derrick

unread,
Jul 4, 2011, 12:46:05 AM7/4/11
to mongodb-user
I have a User model (name: string, friends: array) and a Post model
(message: string) and am trying to figure out the best way to model a
news feed. For example suppose user A is friends with user B. When
user A creates a post, then it should show up in user B's news feed.
What's the best way to model this?

At first glance, I'm thinking of having a feed array field on User,
and populating it whenever a friend creates a post. But if a user has
hundreds of friends, will this become costly (as it will need to post
to all of the friends' feeds)?

Any thoughts on how to best model this?

Sam Millman

unread,
Jul 4, 2011, 8:58:46 AM7/4/11
to mongod...@googlegroups.com
"At first glance, I'm thinking of having a feed array field on User,
and populating it whenever a friend creates a post. But if a user has
hundreds of friends, will this become costly (as it will need to post
to all of the friends' feeds)?"

You mean putting all wall posts within a field within the user document.

If so that will not work because:

- Document size is only 16meg
- Sorting and picking out individual wall posts etc would be too tiresome and expensive.

You will need two collections. One for user and one for wall and one for friends.

You gather together all the friend ids and then search for wall posts that are from that user and are not private or directly to another user that is not the one viewing.

This is only a basic outline of what to do but should be enugh to get you on your way.

Hope this helps,


--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.


Martin Wawrusch

unread,
Jul 4, 2011, 9:05:38 AM7/4/11
to mongod...@googlegroups.com
here is a detailed discussion of the topic, although not mongodb specific:


HTH
Martin

Kyle Banker

unread,
Jul 5, 2011, 10:57:20 AM7/5/11
to mongodb-user
This talk also presents an interesting way of doing this:
http://www.10gen.com/presentation/mongosf2011/schemascale

Sometimes you can get away with building the news feed dynamically.
But for the most read-intensive applications, you'll probably want to
denormalize. If you do, I'd recommend storing a given user's feed in
buckets, as described in the talk I linked to.

On Jul 4, 9:05 am, Martin Wawrusch <mar...@wawrusch.com> wrote:
> here is a detailed discussion of the topic, although not mongodb specific:
>
> http://www.quora.com/What-are-best-practices-for-building-something-l...
>
> HTH
> Martin
>
>
>
>
>
>
>
> On Mon, Jul 4, 2011 at 5:58 AM, Sam Millman <sam.mill...@gmail.com> wrote:
> > "At first glance, I'm thinking of having a feed array field on User,
> > and populating it whenever a friend creates a post. But if a user has
> > hundreds of friends, will this become costly (as it will need to post
> > to all of the friends' feeds)?"
>
> > You mean putting all wall posts within a field within the user document.
>
> > If so that will not work because:
>
> > - Document size is only 16meg
> > - Sorting and picking out individual wall posts etc would be too tiresome
> > and expensive.
>
> > You will need two collections. One for user and one for wall and one for
> > friends.
>
> > You gather together all the friend ids and then search for wall posts that
> > are from that user and are not private or directly to another user that is
> > not the one viewing.
>
> > This is only a basic outline of what to do but should be enugh to get you
> > on your way.
>
> > Hope this helps,
>
Reply all
Reply to author
Forward
0 new messages