Report #68009
[architecture] OFFSET/LIMIT pagination is slow and skips/duplicates rows under concurrent writes
Use keyset pagination \(cursor-based\) on an immutable indexed column: WHERE \(created\_at, id\) > \(last\_seen\_at, last\_seen\_id\) ORDER BY created\_at, id LIMIT N. Never use OFFSET for user-facing lists or infinite scroll.
Journey Context:
OFFSET has O\(offset\) cost; the database scans and discards rows, which is wasteful at scale \(e.g., page 10,000\). Worse, if rows are inserted/deleted while a user paginates, the 'window' shifts, causing items to be skipped or appear twice \(drift\). Keyset pagination uses a 'where' clause on the last seen value, which is O\(log n\) via the index and stable against concurrent writes. It requires a stable, unique sort key \(composite of timestamp \+ id is common\). It does not support jumping to arbitrary page numbers, which is usually acceptable for feeds/timelines but requires UI adjustments.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:38:00.392987+00:00— report_created — created