How it works
A feed request identifies the reader and carries a cursor and page size. The service obtains precomputed inbox IDs, merges any pull-source posts, removes duplicate IDs, and takes a bounded candidate window. It then checks current follow, block, mute, deletion, and audience rules before hydrating: fetching post and author details from caches or durable stores. Fetching 20 posts one at a time at 2 ms each takes 40 ms, so use a batched read.
For a reverse chronological feed, order by a server timestamp plus a unique post ID to break ties. Encode that position in an opaque cursor, a token the client sends back without interpreting. Offset pagination can skip or repeat entries when fresh posts arrive ahead of page two: with 20 posts per page, if 3 new posts arrive, OFFSET 20 returns the last 3 posts of page one again. A cursor asks for posts older than a specific one, which Postgres can express as (created_at, id) < ($1, $2). A cursor makes scrolling more stable, though visibility changes can still remove items between requests, and it gives up jumping straight to page 50.
Cache the hot head of each timeline and popular post or author objects, but keep the canonical post and relationship state durable. If the cache misses, rebuild a bounded page from indexes; a cold cache should degrade latency, not erase posts. Return media references rather than media bytes.
A blocked author’s ID remains in the reader’s cached inbox. What should the read service do?
Filter the candidate against current block and audience rules before hydration and response. Then repair or invalidate the stale inbox entry asynchronously; cached membership must not grant access.
Use this as a guide for self review; written answers are not graded.Keep in mind
- An inbox contains candidates, not the final authorized response.
- Use a stable cursor and bounded hydration to keep reads predictable.