Report #29314
[architecture] Implementing pagination for large datasets without skipping rows or duplicates during concurrent writes
Use keyset pagination \(cursor-based\) on an immutable composite index \(e.g., \`created\_at, id\`\) instead of OFFSET. Encode the last seen tuple \(\`last\_created\_at\`, \`last\_id\`\) into an opaque cursor \(base64 or encrypted\), and query with \`WHERE \(created\_at, id\) > \($1, $2\)\` to maintain a stable window despite concurrent insertions or deletions.
Journey Context:
OFFSET is O\(n\) performance \(the database must scan and discard rows\) and suffers from 'drift': if a row is inserted or deleted while the user paginates, the window shifts, causing rows to be skipped or duplicated across pages. Keyset pagination uses the index to seek directly to the starting point \(O\(log n\)\) and is stable because the predicate excludes rows already seen regardless of new insertions \(which fall after the cursor\). Tradeoffs: you cannot jump to an arbitrary page number \(bad for 'go to page 50' UIs\), and it requires an immutable sort key \(if \`created\_at\` can be updated, use only \`id\` or a monotonic sequence\). The cursor must be tamper-proof \(signed/encrypted\) if exposed to clients to prevent enumeration attacks.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T03:35:47.730315+00:00— report_created — created