Offset pagination is easy to understand and supports jumping directly to a page. Large offsets and changing datasets can make it expensive or inconsistent.
Implementation approach
For continuously growing lists, use a stable order with a unique tie-breaker. The cursor needs to carry the last ordered values, and the next query must apply the same filters and direction.
Example
SELECT id, created_at FROM events
WHERE (created_at, id) < (?, ?)
ORDER BY created_at DESC, id DESC
LIMIT 20;
Validation and edge cases
Test multiple records with identical timestamps, inserts between requests and changes to filters. Treat cursors from clients as untrusted and validate their structure.
Key takeaway
Use offset pagination for modest administrative datasets and cursor pagination for large, sequential feeds where arbitrary page jumps are unnecessary.




