Report #81704
[architecture] Offset pagination causing performance degradation and missing rows during concurrent writes
Replace LIMIT/OFFSET with keyset pagination using UUIDv7 \(or ULID\) as the cursor column; query \`WHERE \(created\_at, id\) > \(last\_seen\_ts, last\_seen\_id\) ORDER BY created\_at, id LIMIT n\` with a composite index on \(created\_at, id\)
Journey Context:
Offset scans require counting through discarded rows, getting slower as page number grows; additionally, inserts during pagination cause rows to shift, leading to skipped or duplicated items. UUIDv7 embeds a timestamp in the high bits, providing time-sortability without central coordination, unlike UUIDv4 which causes index bloat in B-trees due to random insertion. KSUID is similar but larger. Tradeoff: UUIDv7 exposes creation timestamp \(information leakage\) and is slightly larger than bigserial \(16 bytes vs 8 bytes\), but avoids sequence bottlenecks in distributed systems. Do not use 'created\_at' alone as cursor unless strictly monotonic \(clock skew breaks it\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:44:12.796007+00:00— report_created — created