Pattern: Feeds and cursor pagination

Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.

Search terms: pagination, cursor, offset, infinite scroll, feed, keyset, page token, video autoplay, list performance, consistent counts

Last reviewed:

For agents

1. Problem

Feeds that use OFFSET get slower with every page, repeat or skip items when new content arrives, and rebuild the whole list when one item changes. Many simultaneous players or timers drain phones.

2. Options

Method Upside Downside
Page number plus OFFSET Simple; jump to page N PostgreSQL still computes the skipped rows, so large offsets are inefficient (its manual says so); items shift when data changes
Cursor (keyset) pagination (recommended) Constant cost per page; stable under inserts No jump to page N; needs a stable sort key
Opaque page token The server can change the cursor format freely; Google’s API guidelines describe page tokens Slightly more code

4. Scenarios and edge cases

5. Common mistakes

6. How to audit

Sources