What Is Pagination? β Definition and How It Works
Learn what pagination is, why result sets are split, the main schemes and their trade-offs, and how to traverse one completely.
Pagination splits a large result set into smaller pages delivered one at a time. It exists because returning everything is impractical for the server, the network, and the consumer alike.
1. Why Results Are Split
- Server cost. Assembling a million rows for one request is expensive.
- Transfer size. Large payloads are slow and fragile.
- Consumer memory. Clients cannot always hold the whole set.
- Perceived speed. A first page arrives quickly.
- Fair use. Bounded responses stop one caller consuming the service.
2. The Schemes
| Scheme | Position expressed as | Stable under change |
|---|---|---|
| Offset and limit | A row count to skip | No |
| Page number | A page index | No |
| Cursor | An opaque marker | Yes |
| Link headers | Server-supplied URLs | Depends on the underlying scheme |
| Time-based | A timestamp boundary | Mostly, with a tiebreaker |
3. The Drift Problem
Counting schemes assume the set does not change between requests. Real data changes: an item inserted before your current position shifts everything after it, so a client skips a row; a deletion causes a repeat.
Cursors avoid this by encoding a position in a sort order rather than a count β which is why large APIs converge on them regardless of the convenience cost.
4. Traversing Completely
- Follow the server's next indicator, not a computed offset.
- Stop on an explicit end signal, not a short page.
- Deduplicate on a stable identifier as you write.
- Cap the loop, and log when the cap is reached.
- Verify the total against expectations before trusting the result.
5. Depth Limits Are Common
Many sources cap how deep pagination can go, returning empty or repeating pages beyond a threshold. This is a defensive measure, not a bug.
The workaround is to narrow the query β by category, date range, or price band β so each traversal stays within the limit, and the full set is collected as several bounded traversals.
6. Pagination in Interfaces Versus APIs
User interfaces favour numbered pages because people want to jump around. APIs favour cursors because correctness matters more than random access.
That is why a site's visible pagination and its underlying API often use different schemes, and the API's is usually the better one to consume.
7. Signals That a Traversal Went Wrong
- Fewer total records than previous runs.
- An overlap rate far above normal.
- The loop hitting its cap.
- Identical pages returned consecutively.
- Total count changing between the first and last page.
Each is worth failing on rather than quietly accepting.
8. Summary
Pagination divides results into pages using offsets, page numbers, cursors, links, or timestamps, with counting schemes vulnerable to drift and cursors stable under change.
Traverse by following the server's own indicator, stop on explicit signals, deduplicate, cap the loop, and validate completeness β a partial traversal reported as complete is the failure that matters.