Cursor Pagination vs Offset Pagination, and Why Testing Page 2 Matters

Pagination looks like a solved problem right up until you test page two of a list that's changing while someone's paging through it — at which point the choice between offset and cursor pagination stops being a style preference and starts being the difference between "works" and "silently skips or duplicates rows."
Offset pagination
The familiar version: ?page=2&limit=20, or ?offset=20&limit=20. Simple to implement, simple to reason about, and it supports jumping straight to an arbitrary page — "go to page 8" is a trivial request. Its weakness shows up specifically when the underlying data changes between page requests: if a row is inserted at the front of the list between you fetching page 1 and page 2, everything shifts by one, and page 2 either repeats a row you already saw or skips one entirely, depending on the direction of the shift. For a list that's mostly static, this rarely matters. For anything resembling a live feed — recent activity, a live-updating table, anything with concurrent writes — it's a real, user-visible bug, not a theoretical one.
Cursor pagination
Instead of "give me items 20 through 40," a cursor-paginated API says "give me the next 20 items after this specific one I already saw" — the cursor is typically an opaque, encoded pointer derived from the last item on the previous page (often based on its id or a sort key), not a raw numeric offset. This is immune to the insert-shifts-everything problem, because "after this specific item" stays correct regardless of what got inserted elsewhere in the list. The tradeoff: you lose the ability to jump to an arbitrary page number, because a cursor only tells you how to get the next page relative to where you are, not how to compute page 8 directly.
Most APIs that need to handle genuinely live, frequently-changing lists at scale — social feeds, activity logs, anything append-heavy — use cursor pagination for exactly this reason, even though offset pagination is simpler to build and to explain.
What's actually worth testing, regardless of which one you use
A few pagination bugs show up across both styles and are worth deliberately checking rather than assuming away:
- The last page returns correctly — no next cursor/next page link, and the client actually stops requesting more instead of looping forever trying to fetch a "next page" that doesn't exist.
- An empty result set is handled — page 1 of a list with zero items shouldn't crash a client that assumed there'd always be at least one item to render.
- A page size boundary is exact — if the API says 20 items per page, page 1 should have exactly 20 (not 19 or 21), and the item that's supposed to be the first item of page 2 shouldn't also appear as the last item of page 1.
- Malformed or expired cursor/page input is rejected with a clear error, not a silent fallback to page 1 that a client might not notice.
Making these reproducible
Testing "does my client correctly stop paging on the last page" against a real, live dataset means either finding (or creating) a dataset with a known, fixed size — annoying to set up and easy to accidentally break by adding a test row elsewhere — or mocking the specific pages you need. A stateful CRUD collection with a known, fixed number of seeded items, or a handful of manually configured routes for page 1/page 2/last-page/empty-page via conditional matching, gets you a pagination fixture that won't drift out from under your tests the way a shared real dataset eventually will.
Xerat02
Building MockBase.
More from the blog

Mock vs Stub vs Spy vs Fake: The Test Double Vocabulary Nobody Agrees On
Developers use "mock" as a catch-all for anything fake in a test, which is exactly backwards from how the term was originally meant — and the actual distinctions aren't pedantry, they're about what a test can and can't tell you when it passes.

Testing Timezones Without Waiting for Next Tuesday
Timezone bugs concentrate at specific real-world moments — a DST transition, a 45-minute UTC offset — which is exactly why testing "today, in the server's timezone" never finds them.