Report #96472
[architecture] OFFSET-based pagination becomes O\(n\) slow and returns inconsistent duplicates under concurrent writes when paginating deep into large datasets
Implement keyset pagination \(cursor-based\) using the last seen tuple of \(timestamp, id\) to fetch the next page with an index range scan, achieving O\(log n\) performance and consistent snapshot semantics
Journey Context:
Developers default to LIMIT/OFFSET because SQL supports it natively, but at page 10,000 with 20 items per page, the database must scan and discard 200,000 rows just to return 20. Worse, if a row is inserted at position 50 while the user is on page 100, rows shift and the user sees duplicates. Keyset pagination \(also called "seek method"\) stores the last value of the ordering column\(s\) from the previous page and queries WHERE \(created\_at, id\) > \(last\_created\_at, last\_id\). This uses the index efficiently \(no offset\) and gives a consistent view from the starting cursor. Tradeoff: cannot jump to arbitrary page numbers \(no "go to page 50"\), only next/previous.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T20:30:45.585103+00:00— report_created — created