|
|
|
Building APIs: A Comparison Between Cursor and Offset Pagination?
|
|
37 points
by kasrakhosravi2
1896 days ago
|
|
I have been mostly relying on offsets for implementing paging. It is more straightforward in implementation but I find cursor based pagination more intuitive in usage; plus it has better support for real-time data but on the negative side you are forced to use infinite scroll which is not always the best solution. I was curious if anybody has any experience with these two approaches in their projects? And what are some other advantages and disadvantages on this? [1] [1] I wrote this piece a while back but was thinking of updating it further: https://betterprogramming.pub/building-apis-a-comparison-between-cursor-and-offset-pagination-88261e3885f8 |
|
You're not forced to. You could instead Show "8964 Results Total: Previous 100 | Next 100 ... Last 100" which in practice is the same as pagination.
Sure the user can't click in the MIDDLE of the page set, but what kind of a use case is that, anyway.
Anyway, cursor offsets are fundamentally O(1), and offsets are fundamentally O(N) where N is the offset. As a younger programmer, I used to wonder what is this algorithmic magic the database uses, so it knows how to compute offset 10000 without sorting and looking at the first 10000 values I sort by. Well? No magic, it just hustles through it and delivers. But slowly.