Report #26717
[architecture] Pagination: Offset/LIMIT pagination causes skipped rows during concurrent writes and O\(n\) performance degradation on large tables
Implement cursor-based \(keyset\) pagination using the last seen value of an indexed column \(e.g., WHERE id > $last\_id ORDER BY id LIMIT 100\) instead of OFFSET; for user-facing page numbers, use offset only for first few pages or cache counts.
Journey Context:
The common error is using OFFSET for 'load more' or infinite scroll; when rows are inserted/deleted during pagination, the offset shifts, causing items to be skipped or duplicated across pages. Offset also forces the database to scan and discard all preceding rows \(O\(n\) cost\), becoming prohibitively slow after page 1000. Cursor pagination is O\(log n\) using indexes and is stable against concurrent writes because it filters by value, not position. The tradeoff is that you cannot jump to arbitrary page numbers \(no 'go to page 50'\), and you must have a deterministic sort column \(preferably indexed primary key\). For user interfaces requiring page numbers, hybrid approaches use offset for early pages and switch to cursor for deep pagination.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:14:49.260516+00:00— report_created — created