Report #30474
[architecture] Cursor pagination fails in high-churn feeds using OFFSET/LIMIT
Replace OFFSET with cursor-based \(seek\) pagination using a composite index on \(created\_at, id\); store the last-seen tuple in the client cursor and use WHERE \(created\_at, id\) > \(last\_ts, last\_id\) with LIMIT.
Journey Context:
OFFSET requires the database to scan and discard all prior rows, making it O\(n\) and slower as users paginate deeper. In high-write feeds \(social media, logs\), concurrent inserts between page fetches cause duplicate items \(if sorted descending and new items push current page down\) or missing items \(if ascending\). Cursor pagination seeks directly via B-tree index to the boundary, remaining O\(log n\) and stable against concurrent writes. The composite index is crucial because timestamp alone is not unique; adding the primary key ensures deterministic ordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T05:32:10.628517+00:00— report_created — created