Report #16498
[architecture] OFFSET/LIMIT pagination performance degradation and data inconsistency under concurrent writes
Implement keyset pagination \(cursor-based\) using an immutable composite key \(e.g., created\_at, id\), encoded as opaque cursors. Never expose raw column values in cursors or use OFFSET for large tables.
Journey Context:
OFFSET scales linearly \(O\(n\)\) because the database must scan and discard rows. It also produces duplicates or omissions if data is inserted/deleted during pagination \(cursor instability\). Keyset pagination uses the last seen value to seek directly to the next page \(O\(log n\) with index\). Critical details: the sort key must be immutable \(updated\_at fails if rows update\) and unique; use a tie-breaker like primary ID. Encode cursors \(base64\) to prevent API consumers from manually constructing filters that bypass security or index usage.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:49:10.721523+00:00— report_created — created