This guide is written for developers who want a practical answer, not a giant theory dump. The goal is to help you understand the decision, use the idea in a real project, and explain it clearly in an interview or code review.
Quick answer
Offset pagination is simple for small lists. Cursor pagination is usually better for large or frequently changing lists.
Why developers search this
Pagination is searched by developers building feeds, dashboards, search results, and admin tables.
It is a good SEO topic because the search usually happens near a real task: fixing a broken build, choosing an architecture pattern, deploying an app, reviewing AI-generated code, or preparing portfolio proof. Those searches are more valuable than broad “what is programming?” traffic because the reader needs an answer they can use today.
Mental model
Pagination is not only UI. It is a database query pattern, a consistency decision, and an API contract.
| Type | Best for |
|---|---|
| Offset | Small admin tables and jump-to-page interfaces |
| Cursor | Feeds, infinite scroll, large lists, changing data |
| Keyset | Stable ordering by indexed columns |
Practical example
SELECT *
FROM posts
WHERE created_at < $1
ORDER BY created_at DESC
LIMIT 20;
This example is intentionally small. In a real codebase, the surrounding details matter: naming, error handling, tests, runtime config, permissions, and how easy the next developer can understand the change.
Implementation checklist
- Choose a stable sort order.
- Include a tie-breaker such as id.
- Encode cursors so clients do not depend on internals.
- Index the pagination columns.
- Document whether new items can shift results.
Common mistakes
- Using offset for huge tables.
- Sorting without a stable tie-breaker.
- Returning raw database ids as magical cursors without thought.
- Ignoring deleted or inserted rows between pages.
- Forgetting total counts can be expensive.
How to explain this in an interview
Use a concrete sentence:
I used this pattern because [problem]. The main tradeoff was [tradeoff]. I verified it by [test or check].
That structure works because it shows judgment. Anyone can name a tool. Strong developers explain why they chose it, what could go wrong, and how they checked the result.
Related guides
- postgres indexes explained backend developers
- api error response format nodejs
- database transactions explained backend developers
Sources checked
Final takeaway
Offset pagination is simple for small lists. Cursor pagination is usually better for large or frequently changing lists. Keep the implementation small, verify the edge cases, and write the decision down so the next person can trust it.
Discussion
What would you try, change, or challenge after reading this guide? Specific results and errors help the next reader.
Comments will load as you reach this section.