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?