Paginating Requests in APIs

Should all APIs use Cursor-based pagination? Learn the different pagination strategies available and their advantages and disadvantages

Page — based pagination

Example of API requests using Page-based pagination.
SQL query generated by page-based pagination.

“The larger the offset, the slower the request is, up until the point that it times out.” Shopify Blog

KeySet-based pagination

Example of API requests using KeySet-based pagination.
Example of the SQL query generated using KeySet-based pagination.

Cursor-based pagination

Example of API requests using Cursor-based pagination.

Usages in the industry

Stripe

Both parameters take an existing object ID value and return objects in reverse chronological order. The ending_before parameter returns objects listed before the named object, and the starting_after parameter returns objects listed after the named object. These parameters are mutually exclusive -- only one of starting_after orending_before may be used.

Stripe Requests API

Facebook:

Cursor-based pagination is the most efficient method of paging and should always be used when possible.Facebook API Docs

Slack API

Shopify:

Shopify API example using Cursor-based Pagination

Github:

Popular APIs pagination mechanisms

Conclusions

--

--

Staff Software Engineer at Shopify. Opinions are my own. ignaciochiazzo.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store