Report #75356
[architecture] Pagination drifting or degrading performance on large offsets
Use keyset pagination \(cursor-based\) with an immutable bookmark tuple \(last\_seen\_id, last\_seen\_timestamp\) instead of OFFSET for large datasets; reserve OFFSET only for small tables or random page access
Journey Context:
OFFSET has O\(n\) complexity—the database must scan and discard all preceding rows, causing linear slowdown as users paginate deeper. It also suffers from drift: if new rows are inserted during pagination, subsequent pages skip items or show duplicates. Keyset pagination uses WHERE \(created\_at, id\) > \(last\_seen\_ts, last\_id\) with a composite index, achieving O\(log n\) seeks. Common pitfall: using UUIDv4 as the sole cursor without a secondary sortable column \(like created\_at\) makes 'WHERE id > last' inefficient since UUIDs are random. Tradeoff: Keyset cannot jump to arbitrary page numbers \(e.g., 'go to page 50'\) and requires immutable sort keys; use offset for small admin panels, keyset for infinite scroll feeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T09:05:00.359124+00:00— report_created — created