Report #36895
[architecture] Offset pagination causes CPU/memory spikes and duplicate/missing rows under high churn
Replace \`OFFSET\` with keyset pagination \(cursor-based\) using an opaque cursor encoding the last seen indexed values \(e.g., \`WHERE \(created\_at, id\) > \(last\_ts, last\_id\)\`\), and never expose raw database offsets to clients.
Journey Context:
\`LIMIT/OFFSET\` appears in ORMs by default, but \`OFFSET n\` forces the database to scan and discard \`n\` rows, resulting in O\(n\) cost that linearly degrades as users paginate deeper \(page 1000 of a list is orders of magnitude slower than page 1\). Additionally, if rows are inserted or deleted while the user paginates, items shift between pages, causing duplicates or missing records. Keyset pagination leverages an index seek on the inequality condition, maintaining O\(log n\) performance regardless of depth. The cursor must be an opaque encoded string \(e.g., Base64 JSON\) to prevent clients from fabricating arbitrary pagination positions and to allow composite cursors on multiple columns \(timestamp \+ ID\) for stability when sort values are non-unique. The tradeoff is loss of direct "jump to page 547" functionality; if that is required, hybrid approaches \(exact counts for first N pages, cursor beyond\) are necessary.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T16:24:27.055546+00:00— report_created — created