← Lessons

quiz vs the machine

Gold1390

System Design

Feed Pagination With Cursors

Why feeds page by cursor instead of offset to stay correct as content shifts.

4 min read · core · beat Gold to climb

Paging a moving stream

A feed is too long to send at once, so the client requests it in pages. The naive way is an offset, give me items twenty to forty. But a feed changes between requests as new posts arrive, which breaks offsets.

With offset paging, a new post inserted at the top shifts everything down. The next page then repeats an item the user already saw, or skips one entirely.

Cursor based paging

A cursor is an opaque token marking a position in the stream, often the id or score of the last item returned. The client sends back the cursor, and the server returns items after that position.

  • New posts at the top do not shift the cursor, so no duplicates or gaps.
  • The query becomes give me items after this id, which indexes cleanly.
  • The cursor is opaque, letting the server change its internals without breaking clients.

Why this matters for feeds

Feeds are append heavy and constantly changing, the exact case where offsets fail. Cursors give stable, efficient forward paging that survives new content arriving mid scroll.

Key idea

Feeds page with opaque cursors that mark a stream position, avoiding the duplicates and gaps that offset paging causes when new content arrives mid scroll.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does offset paging break on a live feed?

2. What does a cursor typically encode?

3. Why keep the cursor opaque?