intermediateScaling Patterns

Paginate a Growing Feed

Decide what you would build from the brief alone. Everything below it is available, but the exercise stops working if you open it first.

The brief you were given

GET /feed returns every item. The table has grown and the endpoint is now slow and occasionally times out. Add pagination.

The trap — the wrong fix that looks right

Adding LIMIT and OFFSET and confirming that page 1 and page 2 look right. They do, in a test database where nothing is being inserted. In production, items arrive continuously at the top of the feed, so by the time the client asks for page 2 the whole window has shifted by the number of new items — and the user never sees the ones that slid across the boundary. The bug is invisible in every test and reported as "the feed skips things".