- Newest
- Most votes
- Most comments
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
Relevant content
- Accepted Answerasked 10 days ago
- asked 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated 2 months ago