Report #87344
[architecture] How to implement stable pagination in high-write systems where OFFSET/LIMIT causes skipped or duplicate results under concurrent writes
Implement cursor pagination using an opaque cursor encoding the last seen values of the sort columns \(typically created\_at \+ id\). Query using WHERE \(created\_at > $cursor\_timestamp\) OR \(created\_at = $cursor\_timestamp AND id > $cursor\_id\), with an index on \(created\_at, id\). Never use OFFSET for pagination in production systems with concurrent writes.
Journey Context:
OFFSET/LIMIT pagination is simple but fundamentally flawed under concurrent modification: if a row is inserted at position N while the user views page 2, the user sees item X again on page 3 \(duplicates\) or misses items \(skips\). Additionally, OFFSET requires scanning and discarding rows, causing O\(n^2\) performance degradation. Cursor pagination \(keyset pagination\) treats the dataset as a sorted set and fetches the next page relative to the last seen item, making it stable against insertions/deletions elsewhere in the set. The cursor must encode the full sort key \(timestamp alone isn't sufficient due to collisions, hence composite \(timestamp, id\)\). Tradeoff: You cannot jump to arbitrary page numbers \(no 'go to page 50'\), and implementing backward pagination requires reversing the sort order or using a different cursor.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:11:53.822263+00:00— report_created — created