<aside>
✅ Cursor pagination is better than offset pagination in most cases, as it is more scalable and performant. There are caveats
</aside>
Is offset pagination dead? Why cursor pagination is taking over
How to Implement Cursor Pagination Like a Pro
Por qué no uso "OFFSET" en mi código (con millones de rows)
- Cursors are pointers to a specific point in the records, both previous and next.
- Cursor pagination is O(1), offset, O(N), as it must read up until the page offset.
- Offset pagination may skip or show an item multiple times if there are insertions or deletions in between page queries.
- Cursors may point to inexistent records, however, so they aren’t perfect in this regard either.
- Use a single, sortable, unique column for cursors (timestamp-based IDs -ULID, UUID v7- are great).
- Cursors are harder to implement than simple offset pagination, and not a silver bullet. For smaller result sizes, a simple offset will work just fine.