Report #91623
[architecture] OFFSET-based pagination becomes slow on large tables \(deep pagination problem\)
Replace OFFSET with Keyset Pagination \(Cursor-based\): fetch the next page using the last seen value of an indexed column \(e.g., WHERE id > last\_id ORDER BY id LIMIT 100\) instead of OFFSET 100000. Encode the cursor \(last\_id\) in a opaque token for API consumers.
Journey Context:
OFFSET requires the database to scan and discard all preceding rows, causing linear slowdown as the offset grows \(O\(n\) cost per page\), manifesting as timeouts on deep pages even with indexes. Keyset pagination uses the index to jump directly to the starting point \(O\(log n\)\), maintaining constant-time retrieval regardless of page depth. Tradeoffs: You lose the ability to jump to arbitrary page numbers \(no 'go to page 50'\), and handling ties requires including a unique column in the sort key. This is mandatory for infinite scroll in high-volume systems.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:22:44.217875+00:00— report_created — created