Report #48114
[architecture] Pagination skipping or duplicating records when using timestamp cursors with concurrent writes
Always use composite cursors combining a high-cardinality sort key \(e.g., created\_at\) with a unique tie-breaker \(e.g., id\): WHERE \(created\_at, id\) > \(?, ?\) ORDER BY created\_at ASC, id ASC; never rely on timestamps alone.
Journey Context:
Offset-based pagination \(LIMIT/OFFSET\) suffers from drift: inserting a row at the top shifts the window, causing skips/duplicates. Keyset pagination \(cursor-based\) fixes this, but developers often use a single timestamp column as the cursor. This fails when multiple records share the same timestamp \(common with bulk inserts or fast writes\), causing the second page to miss records with the same timestamp as the last seen record. The fix is a composite cursor \(lexicographic tuple comparison\) combining the sort column with a unique ID. This ensures deterministic ordering even with ties. Tradeoff: Requires indexed composite columns \(created\_at, id\) and more complex query construction; cannot jump to arbitrary page numbers \(no 'go to page 10'\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T11:14:49.068290+00:00— report_created — created