Follow-up round: a new post arrives while you scroll
The setup
You designed a news feed. The app loads page 1, then page 2, as the user scrolls.
The question
The interviewer asks: "While the user reads page 1, ten new posts arrive. What does page 2 show?"
Stop here and answer out loud for one minute.
A weak reply
"The next 20 posts." With page numbers, the server counts from the top of the list. Ten new posts push the old ones down ten rows, so page 2 starts with ten posts the user has already seen.
A strong reply
- Page numbers break when the list changes while the user reads. A new item at the top makes an item repeat. A delete above makes an item get missed.
- I use a cursor. It is a saved place in the list. The server gives it with each page, and the app sends it back to ask for the next one.
- The server asks for "the items after this one". New posts at the top do not change what comes after it.
The twist many people miss
The interviewer asks: "The feed is ranked, and the server re-ranks it between two requests."
A good answer: a cursor does not stop this. A post can move from page 3 to page 1. So the server should keep the ranked list fixed behind the cursor, and the app should still keep one row for each post ID. I would do the second even if the server does the first.
Check yourself
- Did you say why a page number moves when the top changes?
- Did you say what a cursor is, and that the app does not read it?
- Did you cover the ranked feed and the repeats by post ID?
Score your answer on the score sheet.
Go deeper
- Cursor vs offset guide
- News feed case
- Pagination race: press the buttons and watch the repeats and the missed posts.
Get the follow-up round by email
One short email each week. The cheat sheet comes with the first one.
You confirm your address first. Unsubscribe any time. Privacy.