Offset pagination repeats or skips records when the list changes between requests; cursor (keyset) pagination does not, as long as the server defines a total order and treats the cursor as an opaque position. A cursor still does not freeze the dataset, so the API also has to say whether a multi-page walk is live, bounded or tied to a snapshot. Checked November 29, 2026 against GitHub, Stripe, Google’s API design guide and PostgreSQL.
Offset versus cursor: the same change, two results
Take nine orders, newest first, with IDs 9 down to 1, and a page size of 3. A client reads page 1 and gets orders 9, 8 and 7. Then the list changes before the next request. The table shows what page 2 returns in each case (worked by hand from the definitions of OFFSET and keyset order, not from a product test).
| Change after page 1 | Offset page 2 (offset=3) | Cursor page 2 (after order 7) |
|---|---|---|
| Nothing | 6, 5, 4 | 6, 5, 4 |
| New order 10 is inserted | 7, 6, 5 (order 7 appears twice) | 6, 5, 4 |
| Order 8 is deleted | 5, 4, 3 (order 6 is never shown) | 6, 5, 4 |
An offset counts rows from the top of the list as it is now, so any insert or delete above the reader’s position shifts every later page. A cursor says “continue after this record”, so those changes fall on the other side of the position. Changes below the position still show up, which is why the next section matters.
Start with a total order
A list endpoint needs an order that can place every record unambiguously. Sorting by a timestamp alone is usually not enough: two records can share the same timestamp. Add a stable tie-breaker, such as an immutable ID.
A useful order might be:
created_at DESC, id DESC
The cursor should carry both values. If it carries only the timestamp, the server has no reliable way to continue inside a group of records created at the same instant.
The same rule applies to ascending lists. The exact direction matters less than the promise that one item cannot move around because the comparison is incomplete.
How three published APIs define the contract
| GitHub REST | Stripe API v1 lists | Google API design guide (AIP-158) | |
|---|---|---|---|
| Continuation | Follow the URLs in the Link header (next, prev, first, last) | starting_after or ending_before with an object ID; has_more says if there is another page | page_token from next_page_token; no token means no more pages |
| Page size | per_page; most endpoints allow up to 100, and a larger value is reduced to the maximum without an error | limit, 1 to 100, default 10 | page_size; the API documents its default, and a value above the maximum is coerced down |
| Position type | Varies by endpoint (page numbers, or before, after, since) | An existing object ID | Opaque token |
| Rules for the client | Use the returned URLs | The two cursor parameters are mutually exclusive | All other parameters must match the call that produced the token |
Stripe also states that its /v2 namespace has a different pagination interface than v1, which is a reminder that a pagination contract is part of an API version. Google’s guide goes further on opacity: page tokens must be opaque, URL-safe strings that users cannot parse, because parseable tokens turn implementation details into API surface, and base64 encoding a readable token is not enough obfuscation.
The shared point is that the server owns the continuation contract. A client should treat the returned next link or cursor as opaque. Rebuilding it from visible fields couples the client to implementation details and makes later changes much harder.
Decide what happens when the list changes
A cursor preserves a position in an order. It does not automatically preserve a snapshot.
Imagine a client fetching the first 50 newest orders. Before the second request, three newer orders arrive. With a correctly implemented keyset cursor, those new records sit before the client’s current position and do not create duplicates in the rest of the walk. That is often the right behavior for an activity feed.
Now imagine an export that promises an exact account balance report. “Everything that happened to be in each page when we asked” is not a useful definition. The export needs a time boundary or a stable snapshot.
There are three common contracts:
- Live walk. Each page uses current data, but continuation remains stable relative to the last item. New records may be outside the remainder of the walk.
- Bounded walk. The first response fixes an upper boundary such as
created_at <= 2026-10-15T07:00:00Z. Every later page repeats or embeds that boundary. - Snapshot walk. The server keeps a database or materialized snapshot and issues a snapshot token. Every page reads the same logical dataset until the token expires.
The right choice depends on the job. A search result can tolerate a live walk. A billing export often cannot.
Database isolation does not automatically span HTTP requests
PostgreSQL documents that Read Committed is its default isolation level, that each SELECT sees only data committed before that query began, and that two successive SELECT commands can see different data when other transactions commit in between. Repeatable Read gives a transaction a stable view from its first statement, but a normal paginated API usually opens a new transaction for every HTTP request.
Keeping one database transaction open across a long client session is rarely a good general solution. It holds resources, complicates failure recovery and can outlive practical connection limits.
If the product needs snapshot semantics, design them explicitly. Options include recording an “as of” boundary, materializing export rows, or saving a server-side snapshot reference with a documented expiry.
Deletions need a rule too
A keyset cursor normally continues after the last key it saw. If that anchor record is deleted, the cursor can still work when it contains the comparison values rather than requiring the row to exist. In the table above, the cursor after order 7 still returns 6, 5 and 4 when order 8 is gone. A Stripe-style cursor that is only an object ID depends on that object still being resolvable, so check how your implementation behaves when the anchor is deleted.
That is another reason not to make a cursor only an encoded database ID. The server may need the sort key, direction, filters and snapshot boundary to reconstruct the next query safely.
Do not put sensitive filter values in a readable token. Sign or encrypt cursors as appropriate, and reject tampered or expired tokens with a clear error.
Keep filters and permissions inside the cursor contract
A continuation token from “paid invoices for customer A” should not be reusable for “all invoices for customer B.” Either embed the normalized query scope in the signed token or verify it against server-side state. Google’s guide states the same requirement from the client side: all other request parameters must match the call that issued the token.
Authorization can also change between requests. The API has to decide whether a snapshot preserves the original authorized set or rechecks access on every page. Rechecking is safer for revoked access, but it may change totals. Document the behavior instead of leaving clients to infer it. The same per-record check is the subject of object-level authorization.
This is closely related to reviewing an OpenAPI contract before release. Cursor formats may be opaque, yet changing ordering, default filters or continuation behavior can still break a client.
What to test before release
Use a test dataset with deliberate ties in the sort field, then mutate it between requests.
Check that:
- every original record appears once in a bounded or snapshot walk;
- a live walk never loops or duplicates an already returned item;
- inserts before and after the cursor behave as documented;
- deletion of the anchor record does not break continuation;
- changing the page size preserves position;
- expired, malformed and cross-scope cursors fail clearly;
- the final response has an unambiguous end condition;
- retrying the same request returns a compatible page, which matters when a client backs off after a rate limit, as in HTTP rate limits and client backoff.
Also test large walks without collecting every item in memory. GitHub’s Octokit documentation, for example, offers an iterator so clients can process one page at a time.
A practical response shape
A small, explicit envelope is easier to evolve than a bare array:
{
"data": [],
"next_cursor": "opaque-token",
"has_more": true,
"as_of": "2026-10-15T07:00:00Z"
}
Do not include as_of unless it means something precise. If it is only the response time, name it accordingly. A timestamp that looks like a snapshot promise but is not one creates more confusion than it removes.
The design test is simple: can the API explain what a complete walk represents while records are being inserted, updated and deleted? If the answer is vague, the pagination contract is unfinished.





