Pagination Options & Support #25
Replies: 1 comment 8 replies
-
Great feedback! For reference, the original reason(s) that offset pagination was suggested as the preferred default was mostly aligned to the "lowest common denominator". Most teams at SPS Commerce ARE NOT doing cursor-based pagination (some are though, like Transaction API). The reality that I'm perceiving is that the volume and frequency of data for many APIs at SPS on resources that have pagination do not suffer from performance issues. This could mean that the granularity of data and volume for a designed service will never result in problems, or it's a problem that will come in the future for some services as they grow. We also referenced industry-similar APIs, many of which use offset, e.g. https://developer.walmart.com/api/us/mp/orders#operation/getAllReleasedOrders Though by no means do I think this is a great criterion to make decisions on the Standards. Many teams who are unfamiliar with cursor-based pagination and with services that do not require its advantages may suffer some velocity loss over-burdening them with a required pagination mechanism. To a larger degree, this is why simple and advanced filtering exists as well. The same could be said for offset-based (simple) and cursor-based (advanced). However, to be fare, the degree of difference in pagination implementation from a technical standpoint seems far less burdening than the differences in filtering implementation. In previous discussions, @alexander-ivakhnenko points out, and your suggestion as well @mkokotovich, it does seem like there is a shift in cursor-based pagination being the default standard in the industry for the major APIs we look at as examples: The advantage of course in moving in that direction as well would be to offer a consistent paging mechanism/contract that was guaranteed across our API platform, with some APIs implementing offset-based pagination potentially when needed, rather than most APIs implementing one or the other without consistency. Additionally, this has the advantage of ensuring we do not have breaking API contracts in an API as it begins to discover performance issues over time. While cursor-based pagination can be added in a non-breaking way, it is difficult to remove the old pagination method which may have performance degradation. It also makes it a bit ambiguous which URLs are provided in the "paging" response model (offset-based URLs or cursor-based URLs) by default (that being said, this kind of non-breaking transition is the promise of hypermedia). See some thoughts on Shopify's transition: https://shopify.engineering/pagination-relative-cursors Some additional examples and support for reference:
It is also worth noting the original SPS DevCenter standards actually do indicate the preference for cursor over offset as well: https://developercenter.spscommerce.com/#/docs/api-standards/pagination. Cursor-based pagination works with mostly unique indexes or fields of data to key off. This would not work for requesting data that can be sorted on additional columns as part of the API (unless built into the cursor opaque URL and all fields were largely unique - which would be unlikely). This is a good representation where if APIs had this requirement, would they then be required to implement both? or just offset? Trying to distill the above content into direct questions/answers:
|
Beta Was this translation helpful? Give feedback.
-
I was reading https://spscommerce.github.io/sps-api-standards/standards/collections.html, specifically the section around pagination. As it is currently written, it recommends using limit/offset as the preferred method, and then cursor-based pagination if required by performance concerns.
I am a fan of limit/page (or pageSize/page, etc) as well. It maps well to how the consumers often use pagination (to display multiple pages of results on a UI).
I also have noticed that other companies support cursor-based pagination as the primary method, and then may or may not support limit/offset or pageSize/page in addition. I wonder if we should recommend that all APIs support cursor-based pagination.
Beta Was this translation helpful? Give feedback.
All reactions