Report #49181
[architecture] Offset pagination is slow on large tables with high page numbers
Implement keyset pagination \(cursor-based\) using the last seen value of an indexed column: SELECT \* FROM posts WHERE created\_at < $last\_seen ORDER BY created\_at DESC LIMIT 20; only use OFFSET for small datasets or admin exports where jump-to-page is required.
Journey Context:
OFFSET 1000000 causes the database to scan and discard a million rows, getting slower linearly with page depth. Teams often cache results or use 'search after' UI patterns but keep OFFSET for 'page 5' functionality. Keyset pagination requires a unique, immutable sort key \(usually ID or timestamp\) and cannot jump to arbitrary page numbers \(you must traverse sequentially\). For pages with ties \(same created\_at\), use a composite key \(created\_at, id\). This is the only scalable pattern for feeds, timelines, and infinite scroll.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:02:13.023633+00:00— report_created — created