What's the best way to fetch user Feed depending on users he/she follows?

0

I am currently developing a social media app with amplify and dynamodb in react-native. I have the User, Posts, Shares and Likes models. Now I need to fetch the latest posts including relevant shares and likes for the authenticated user to display on the feed depending on who the user follows. I need to get posts using a Lambda function. So what is the recommended logic to achieve this functionality.

1 Answer
-1

https://www.reddit.com/r/aws/comments/144cakm/best_way_to_do_social_media_home_feed_in_dynamodb/

Global Secondary Index (GSI) Approach: Create a GSI for each user that is a list of users being followed. You will also need another GSI containing the minimal information required for the feed to work. When a user wants to see their feed, they will first query the part of their partition that tells them who they follow. Then do a batch get on all those ids on the GSI with the minimal information. Return all that data and sort the data on the client. However, this has the potential to go over 1MB of data returned, which could be an edge case where you have one user following several thousand people​.

Triple Query Approach: This approach includes a query to get all the followers, a second query to get all those followers by some metric like post view count, and then take the top ten post post ids from that query and get the posts needed for the feed. This method involves combining two and three queries, which might be more efficient depending on your needs​.

Pagination Approach: This approach involves querying posts from each blogger the user is following, then sorting and returning a subset of these posts. This could present a problem with pagination, as it requires loading many posts each time the user scrolls through their feed​.

Data Duplication and Dynamo Stream Approach: Another suggestion is to duplicate the articles for each user and use a dynamo stream to update all duplicates in case the article is edited. For this, you might want to use an index to allow inverted queries. You can also maintain the subscriptions as an array on user level and use something like a step function to parallel query all articles​.

It's worth noting that DynamoDB may not be the optimal solution for globally sorted queries. AWS DocumentDB (which is MongoDB basically) could be a potential alternative. DynamoDB works best when the data can be broken down into many disconnected parts, and is most performant when queries do not span more than one chunk of data at a time​

profile picture
EXPERT
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions