10 private links
Learn about what REST API pagination means, the different pagination patterns that exist, and some best practices when using any type of pagination.
Keyset pagination, or the seek method, is tailored for scenarios that involve large or frequently-updated data sets. It involves using a specific field (or set of fields) as a key to paginate through the data set. This key is usually a unique and sequentially ordered column—for example, a timestamp or an auto-incrementing ID.
To help bring this method to life, let's review an example request:
GET /api/events?since_id=12345&limit=10
Cursor-based pagination excels in efficiently navigating through vast data sets. The way it works is that the API provides a "cursor"—similar to a bookmark—which marks a specific item in the data set. Each request not only retrieves data but also returns a cursor pointing to the start of the next data segment.
Let's review an example of cursor-based pagination:
GET /api/messages?cursor=abc123&limit=10
Unlike keyset pagination, cursor-based pagination uses the cursor—a backend-determined value not necessarily linked to any data fields—to retrieve data from our API. This cursor allows the backend to be flexible with its strategy for handling data updates and also allows for efficient data retrieval.
He calls it keyset pagination, I call it cursor pagination, but at the end of the day this is still the way to scale a paginated response
Good article on how offset pagination is not the greatest thing in the world (at all)