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.
- Pagination splits a large result set into smaller pages.
- Offset pagination uses a page number, while cursor pagination uses a pointer to the last item.
- It improves performance and avoids sending huge responses at once.
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.
Frequently asked questions
What is the difference between offset and cursor pagination?
Offset uses a position and page size but can skip or repeat rows when data changes, while cursor uses a stable pointer and handles changing data better.
Why not return all results at once?
Large responses are slow, use more memory, and strain the network. Pagination keeps each response small and predictable.
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