'How to avoid Feed Repeatings in Pagination If a New Content is Published. And Redis Usage Best Practice
I'm trying to build an app, it has 2 feeds screens similar to Instagram or this kind of social media apps. In the backend I use .Net Core 5 C# Web API.
- One of the screen has a feed for global users. It contains list of items that ordered by PublishDate in Desc order. And it shows every user the same content by Pagination. Every page has 10 items.
- And the other one is for the users which has logged in. They sees the contents of which the users that are followed by the logged user. Like Personal feed. GlobalFeed-PersonalFeed
There are 3 questions about this architecture.
When a user is in a global feed and scrolls down to get 2nd page, if there are new contents also published, the user will see the same contents again from the first page in the beginning of the 2nd page. How can I avoid from this problem?
How can I use Redis in this situation? I don't want to go to database for every users request to show them the same content. But when I'd like to use redis cache, if I name the first page like "GlobalFeed_Page_1" then I should remove the caches of "GlobalFeed_Page_*" after if a new content is Published. But whether If I don't remove the cache or remove cache, there are complication will happen by going to second page. The complication will be the same like 1st question. The last items of Page 1 would be seen in the beginning of 2nd page.
How can I get content for Personal feed by maximum efficiency? If it is possible to cache the content in Global Feed, and share the relational content to the user which is logged in, then which behaviour do I need to apple? And, If I cache Personalized content for every single user, it's not effective; I should get the personalized content from Global feed to Personal feed, but the global feed has cached by 10 of them like GlobalFeed_Page_1 GlobalFeed_Page_2 etc.. And I can't know which key has which users Posts. Because it's serilalized. And Redis works like Key Value pair. So I can't know what it has in content. So I can't know what are the logged in users followings posts in the serialized Global Feed.
Cache Keys Examples; GlobalFeed_Page_1 : Contains 10 items. And contains all users posts. Without any Filter. (User_1 Post, User_15 Post, User_999 Post, etc.) PersonalFeed_UserID_12_Page_1 : Contains 10 items, which is dependent on User 12.
In the end, I'd like you to give me the best practice for this kind of feed pages like instagram/fb/twitter etc.
I'm not so professional, so please give understandable advices and code examples for the situation. GlobalFeed-Page1-Page2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
