paginationarchitectureapi-design

Offset pagination vs Cursor pagination


I am studying about pagination and I have some questions.

  1. What is the difference between two approches?
  2. Best use-case for a cursor based pagination?
  3. Can cursor based pagination go to a specific page?
  4. Can cursor based pagination go back to the previous page?
  5. Are there any performance differences between the two?

My thoughts

I think cursor based is much more complex which makes offset based pagination more desirable. Only real-time data centric system needs a cursor based pagination.


Solution

  • Cursor pagination is most often used for real-time data due to the frequency new records are added and because when reading data you often see the latest results first. There different scenarios in which offset and cursor pagination make the most sense so it will depend on the data itself and how often new records are added. When querying static data, the performance cost alone may not be enough for you to use a cursor, as the added complexity that comes with it may be more than you need.

    Quoted from this awesome blog post, happy coding!

    Also, check this out:

    Pagination is a solution to this problem that ensures that the server only sends data in small chunks. Cursor-based pagination is our recommended approach over numbered pages, because it eliminates the possibility of skipping items and displaying the same item more than once. In cursor-based pagination, a constant pointer (or cursor) is used to keep track of where in the data set the next items should be fetched from.

    This explanation is from Appolo GraphQL docs.