Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 759
MINJA KIM Avatar asked Apr 18 '19 11:04

MINJA KIM


People also ask

What is cursor pagination?

Cursor-based pagination works by returning a pointer to a specific item in the dataset. On subsequent requests, the server returns results after the given pointer.

What is offset pagination?

Offset-based pagination is a very famous technique wherein the client requests parameters with a specific limit (the number of results) and offset (the number of records that need to be skipped). Offset-based pagination is easy to use and is preferred for static data.

What is keyset pagination?

Keyset pagination (also known as the "seek method") is used to fetch a subset of records from a table quickly. It does this by restricting the set of records returned with a combination of WHERE and LIMIT clauses.


1 Answers

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.

like image 77
Jakša Mališić Avatar answered Sep 22 '22 08:09

Jakša Mališić