Writing
Mobile English

Cursor Pagination and Cache Design for Mobile Lists

Offset pagination breaks the moment data moves. How I page, cache, and invalidate feeds in mobile apps without duplicate or vanishing rows.

  • Published
  • 1 min read
On this page3 sections
  1. Why offset breaks
  2. Cursor pagination
  3. The mobile cache layer

Every app has The List: orders, chats, articles. And every naive list has the same two bugs - duplicated rows and vanishing rows - both caused by offset pagination meeting live data.

Why offset breaks

Page 1 = rows 1-20. A new row is inserted at the top. Page 2 = rows 21-40 - but row 21 is old row 20. Duplicate. Deletions do the reverse: a row silently skips. Users notice; they just call it “the app is buggy”.

Cursor pagination

Page by a stable sort key instead of a position:

text
GET /orders?after=2024-06-01T10:22:00Z_ord_8812&limit=20

The cursor encodes (created_at, id) - the id breaks ties. Inserts and deletes above your cursor no longer shift your window.

sql
SELECT * FROM orders
WHERE (created_at, id) < ($1, $2)
ORDER BY created_at DESC, id DESC
LIMIT 20;

The mobile cache layer

  • Cache pages locally (Hive CE/SQLite) keyed by cursor - the list renders instantly on reopen.
  • Pull-to-refresh fetches from the top and prepends, deduping by id; it never clears the cache first (that is how you get the white flash).
  • Invalidate by entity, not by page: an updated order rewrites that row everywhere it appears.

Boring, predictable lists are a feature. Users cannot name “stable pagination”, but they absolutely feel it.