Report #39308
[architecture] Implementing pagination that skips or duplicates items when underlying data changes during pagination \(drift\)
Use cursor-based \(keyset\) pagination on an immutable composite key \(e.g., created\_at \+ id\) instead of OFFSET; return the last seen cursor to fetch the next page.
Journey Context:
OFFSET requires the database to scan and discard rows, causing O\(n\) performance degradation as users paginate deeper. Worse, concurrent insertions or deletions cause 'drift': a user sees item 10, another user deletes item 5, and the next page shows item 10 again \(duplicate\) or skips the new item 11. Cursor pagination uses WHERE \(created\_at, id\) > \(last\_seen\_timestamp, last\_seen\_id\) with an index, providing O\(log n\) performance and stable results even with concurrent changes. The tradeoff is inability to jump to arbitrary page numbers \(only next/previous\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:27:08.687844+00:00— report_created — created