Report #52884
[architecture] Offset-based pagination causing O\(n\) performance degradation and missed/duplicate rows under concurrent writes
Implement keyset pagination \(cursor-based\) using an indexed composite key \(created\_at, id\); encode the cursor as base64 of last\_seen\_values and use WHERE \(created\_at, id\) > \(cursor\_ts, cursor\_id\)
Journey Context:
OFFSET skips rows in the database engine, causing full table scans for deep pages and inconsistent results if inserts happen between queries. Cursor pagination is O\(log n\) via B-tree index seeks. The composite key handles timestamp collisions \(UUID/ID tie-breaker\). Must ensure monotonic ordering \(use ULIDs or snowflakes if clock skew risk\). Tradeoff is inability to jump to arbitrary page numbers \(no 'go to page 50'\); requires bidirectional cursors \(reverse ORDER BY\) for previous page.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T19:15:35.017775+00:00— report_created — created