Suppose you have multiple users, who can create posts on their own profiles.
If a user goes to his news feed, he’ll see the latest posts from his contacts (yes, similar to fb/insta).
I can think of only three approaches:
A) To know what posts to display, the server can check all the recent posts from the user’s contacts, then sort them by date and return with a limit.
B) Every post from every user is indexed by date, then when a user opens his news feed, the server checks all those documents to see if the users are actually contacts and the posts should be considered or ignored.
C) Every time a user posts to his profile, an id of the post goes to the news feed of every single one of his contacts.
Option C is the one I like the most for now.
Every user would have a doubly-linked list of post blocks, where those post ids would be added.
Eg: find a contact, get his latest post block _id (a document that contains 20 post ids). If the block contains less than 20 posts, add it there, otherwise create a new block, add it there and set it as the head of the linked list.
My guess is that you’d recommend something more professional and complex, and I’d love to know what that would be. Thanks a lot!