Design a Neighborhood News Feed with Black-Box Ranking
Serve a ranked local feed whose order comes from an opaque ranking service, with stable cached pagination and clear consistency trade-offs.
Problem statement
For this exercise, assume a neighborhood social network where every resident is verified into exactly one home neighborhood. Each neighborhood has a fixed list of up to 20 nearby neighborhoods. A resident's home feed shows recent posts from the home neighborhood and its nearby neighborhoods.
Posts are short text updates such as recommendations, lost-pet notices, or local news; media upload, comments, direct messages, ads, notifications, and search are outside scope.
Feed order comes from a ranking service owned by another team. Treat it as a black box: you send it a viewer ID and up to 500 candidate post IDs, and it returns an ordered list of IDs.
It exposes no stable per-post score, may return a different order for the same input on a later call, may drop candidates, and can be slow or unavailable. You cannot change it.
A resident scrolls the feed one page at a time. Within one scrolling session, pages must not repeat or skip posts even though the ranker is not repeatable, so you must decide what to cache and what a cursor means. For this exercise, keep the ranked order on the server; the client holds only an opaque cursor.
Posts published while a resident is scrolling should appear on a fresh first page, not inside the open session. A resident must see their own new post right away.
A post deleted by its author or removed by a moderator must stop appearing on every page read made more than 5 seconds after the removal, including pages of a session that started before the removal. When a resident's home neighborhood changes, reads made more than 5 seconds later must follow the new membership.
Explain the data consistency trade-offs you choose for posts, the candidate index, cached pages, and engagement counts.
What to build
- For this exercise, a verified resident can publish a short text post to their home neighborhood with a retry-safe request and see it at the top of their own feed right away.
- For this exercise, a resident can page through a feed of recent posts from their home and nearby neighborhoods, ordered by the external ranking service, without repeated or skipped posts within one scrolling session; posts published mid-session appear on a fresh first page.
- For this exercise, an author can delete a post and a moderator can remove one, and within 5 seconds the post stops appearing on every later page read, including sessions that were already open.
- For this exercise, when a resident's verified home neighborhood changes, feed reads use the new home and nearby neighborhoods within 5 seconds.
At scale
- For this exercise, assume 10 million daily active residents across 300,000 neighborhoods, with peaks of 15,000 feed page reads and 200 new posts per second. A home neighborhood and its nearby neighborhoods together can hold thousands of posts from the last 14 days, so the feed service must pick at most 500 candidates before each ranking call.
- For this exercise, assume the ranking service accepts at most 500 candidates per call, answers in 150 milliseconds at p95 when healthy, and sometimes fails or times out.
- For this exercise, target 500 milliseconds p95 for a first feed page, which includes one ranking call, and 150 milliseconds p95 for each later page in the same session.
- For this exercise, feed candidates are posts from the last 14 days; a new post should reach neighbors' fresh feeds within 10 seconds, removals must hide a post within 5 seconds, a home-neighborhood change must apply to feed reads within 5 seconds, engagement counts such as likes may lag by up to 1 minute, and a scrolling session lasts up to 30 minutes.