Quick Decision Rule: When Paginating a live 50M-row activity feed where new rows insert continuously and users scroll deeply, choose Keyset / cursor pagination (`WHERE (created_at, id) < ($1, $2) ORDER BY created_at DESC, id DESC LIMIT 50`).
| Trigger Condition | Paginating a live 50M-row activity feed where new rows insert continuously and users scroll deeply |
|---|---|
| Recommended Choice | Keyset / cursor pagination (`WHERE (created_at, id) < ($1, $2) ORDER BY created_at DESC, id DESC LIMIT 50`) |
| Classic Trap | `OFFSET 500000` forces the database to scan and discard 500k rows AND causes duplicate/skipped items whenever new records are inserted at the top. |
| Verification | Audited on 2026-11-23 · Distributed Systems Core · 2026 |
30-SECOND DECISION TRAP CHECK · STORAGE
An activity feed table holds 80M rows with constant inserts. Page 500 (`ORDER BY created_at DESC LIMIT 50 OFFSET 25000`) takes 4.2 seconds and shows duplicate posts as users scroll. What fixes both issues?
OFFSET scans and discards preceding rows and shifts whenever new rows arrive at the top. Keyset/cursor pagination jumps directly to the bookmark via the index in O(log N) with stable results.
Trap: Deep OFFSET pagination degrades linearly and breaks under live inserts; use keyset/cursor pagination.