Report #68219
[architecture] Offset pagination performance degradation and data inconsistency under concurrent writes
Implement keyset pagination \(cursor-based\) using ORDER BY id DESC WHERE id < $last\_seen\_id LIMIT N instead of OFFSET.
Journey Context:
OFFSET is O\(offset\+limit\) requiring the database to scan and discard all skipped rows, causing linear slowdown as users paginate deeper. Worse, under concurrent writes, OFFSET creates duplicates and omissions: if a new row is inserted at the top while the user is on page 1, the former last item of page 1 appears again as the first item of page 2. Cursor pagination uses an immutable index seek \(O\(limit\)\) and maintains consistency because it references a specific point in the ordering. The tradeoff is inability to jump to arbitrary page numbers \(e.g., 'go to page 1000'\), but this is usually acceptable for feeds and infinite-scroll UIs. Requires a composite cursor \(created\_at, id\) for ties.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:59:31.888388+00:00— report_created — created