# Pagination Strategies — REST API Design

Source: https://www.geekswithgeeks.com/en/restapi/api-pagination

> Offset-based vs cursor-based paging through large collections.

## Offset pagination

`?page=3&limit=20` (or `?offset=40&limit=20`) is simple and lets you jump to any page. Its cost: on a large, changing dataset the underlying `OFFSET` gets slower with depth, and items can shift between pages if rows are inserted mid-scroll.

## Cursor pagination

`?after=eyJpZCI6NDgyfQ&limit=20` returns an opaque cursor pointing at the last item seen. It stays fast at any depth and is stable under inserts — the trade-off is you can't jump straight to page 10.

## A bookmark vs a page number

Offset pagination is jumping to a page number in a book — easy, but if pages get inserted before it, you land somewhere else. A cursor is a bookmark stuck at a specific sentence — you always resume exactly where you left off.

## Always cap the page size

Enforce a max `limit` (e.g. 100) server-side regardless of what the client asks for — otherwise one request for `limit=1000000` can take down your database.
