Comparison between Offset and Token Pagination | Shreya

editor-img
Shreya
Sept 28, 2022

Comparison between Offset and Token Pagination

Amazon uses offset-based pagination, notice the standard pagination with all page numbers you can click through 1 2 3 - 400.

media

GitHub uses token-based pagination, notice that instead of standard page numbers, they use Previous and Next buttons.

media

It’s very clear that the two tech giants could not agree on which solution is better!

Why? Well, we’ll need to use an answer developers hate. Because it depends. Let's explore both methods to understand their advantages, limitations, and performance implications.

Offset-based Pagination

Pros

  1. Easy implementation from client and server
  2. Possible to jump to random pages

Cons

  1. Can be unreliable at times when there are frequent changes in the data, as the pagination is working you might run into missing items or duplicate items.
  2. More latency for large datasets

Token-based Pagination

Pros

  1. Improved performance
  2. Consistent results- solves missing and duplicate data problems when the token is chosen properly.

Cons

  1. Clients cannot jump to random pages, they have to traverse through each page one by one
  2. Clients need to manage the next token
  3. Records need to be added sequentially to the database

When to use...?

Offset-based Pagination

  1. Best suited for small datasets
  2. Clients need to jump around pages and can tolerate duplicate and missing rows

Token-based Pagination

  1. Best suited for large datasets
  2. Consistency of entries is critical
  3. Traversing pages is acceptable