Report #59138
[architecture] Pagination using OFFSET/LIMIT in high-velocity datasets causes row skipping/duplication during concurrent writes and O\(n\) performance degradation for deep pages
Implement keyset pagination \(cursor-based\) using a composite cursor of the last seen values: WHERE \(created\_at, id\) > \(last\_created\_at, last\_id\) ORDER BY created\_at, id. Encode cursors opaquely \(e.g., base64\) to prevent tampering, and never expose raw database IDs directly.
Journey Context:
OFFSET requires scanning and discarding all preceding rows, making it increasingly slow for deep pagination \(page 1000 costs 1000x page 1\). Worse, if new rows are inserted during pagination \(e.g., a high-velocity feed\), the 'window' shifts downward: moving from page 1 to page 2 causes the new top item to push the last item of page 1 onto page 2, so the user sees a duplicate entry \(or misses items if rows are deleted\). Cursor pagination uses indexed seeks \(O\(log n\)\) and provides a stable view from a specific point in time. The critical detail: single-column cursors \(e.g., timestamp\) fail with duplicate values \(two items with same created\_at\), causing the second duplicate to be skipped. You MUST use a composite cursor \(sort column \+ unique ID\) to ensure deterministic ordering. Note: This prevents jumping to arbitrary page numbers \(no 'page 50' links\), which requires UI adaptation \(infinite scroll or prev/next only\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:45:12.640914+00:00— report_created — created