What is pagination in an API?
Pagination is breaking a large list of results into smaller pages instead of returning everything at once. If a query could return a million rows, sending them all would be slow and heavy, so the API returns a page at a time. The two common styles are offset based, using page and size, and cursor based, using a pointer to the next item.
The two common styles
- Offset based: /users?page=2&size=20, simple but slower on large offsets.
- Cursor based: /users?after=abc123, faster and stable when data changes.
Offset pagination is easy to build and understand. Cursor pagination performs better on huge datasets and avoids skipping or repeating items when new rows are added while the user pages through.
If asked which is better for large or fast changing data, say cursor based. Explaining that offset pagination can skip or duplicate rows when data changes shows you have thought past the basics.
Common follow up questions
Related interview questions
Want the full API Design guide?
Read every API Design concept with notes, diagrams, and code in one place. Track your progress as you go.
Open the API Design guide All API Design questions