0

Imagine an app like Instagram/Reddit with a feed on the home page.

Problem: We want to show users posts they haven't seen before.

When the user first opens the app, we retrieve 30 latest posts from the backend and show them to the user.

The user sees 10 posts and leaves the app.

At this point, the user has seen post with id 30 - 20 and not seen post with id 19 - 1

When the user comes back the next day, the database in total has 40 posts.

This time, when the API retrieves the latest posts, it also fetches 10 of the same old posts that the user has already seen.

We want to be able to skip the posts that the user has already seen.

Probable solution:

Divide the entire feed into "SEEN" and "UNSEEN" ranges. These ranges can be identified by their start and end markers, or post ids.

For example, when the user leaves the app for the first time, we store it as a range. -> (30,20)

This range identifies posts already seen by the user.

Next time when the user opens the app, we send these ranges to the API, and then the API filters posts such as posts on either side of this range and returned. Posts between this range are not.

Does this make sense? Are there any other/better solutions to this problem?

code
  • 2,115
  • 1
  • 22
  • 46
  • would a simple "events" table work better in this case? I'm not sure what kind of scale you are talking about here but an additional table that just records that user 1 read post 4 on date could be used – MBeale Jan 07 '21 at 13:26
  • @MBeale Thanks for your response. This could work but would eventually make storing and filtering the feed extremely difficult since the number of posts in the feed as well as the number of posts seen by a user will keep increasing. To find a Difference Set poses a scale issue. – code Jan 07 '21 at 13:28
  • 1
    is it critical that the users can see all of the posts? for instance, if the next unseen post is from 2 years ago, is that helpful, or should there be an expiration? That could help with partitioning data if you know that there is a limit on what is shown. – MBeale Jan 07 '21 at 13:35
  • 1
    this question might be better suited for https://softwareengineering.stackexchange.com/ – MBeale Jan 07 '21 at 13:36
  • @MBeale Good point. We actually don't need to track seen/unseen posts as long as there is enough content at the top of the stack. This can definitely reduce the table size and can help us scale. – code Jan 07 '21 at 14:12
  • @MBeale when referring other sites, it is often helpful to point that [cross-posting is frowned upon](https://meta.stackexchange.com/tags/cross-posting/info) – gnat Jan 08 '21 at 06:05

0 Answers0