What Is Cursor-Based Pagination? Tokens and Tradeoffs
Scrapeless Agent Browser lets your automation navigate dynamic result interfaces while your application tracks pagination state and collected records.
TL;DR
- A cursor identifies a continuation position. Treat the token as opaque unless the API explicitly documents its structure.
- Stable ordering needs a deterministic tie-breaker. A timestamp alone may not distinguish records created at the same moment.
- Cursor pagination does not imply a snapshot. Concurrent inserts, deletes, and updates still depend on the service’s consistency contract.
- A checkpoint includes the query as well as the cursor. Store records before advancing the committed continuation state.
A Cursor Continues a Particular Ordered Query
Cursor-based pagination divides a result set into pages and gives the client a position from which to continue. Instead of asking the server to skip a numbered quantity of records, the client returns a continuation value from the preceding response. The server interprets that value within the query’s ordering and filtering rules. A cursor is therefore meaningful in relation to a particular collection traversal.
The word cursor does not prescribe one universal parameter name or data structure. A REST API can expose a next-page token or a next link, while a GraphQL connection can expose edge cursors and page information. Read the selected API’s contract before building a loop. A client that guesses a parameter named cursor may send a valid HTTP request that the service interprets differently from the intended pagination operation.
AIP-158 page-token guidance treats page tokens as opaque and binds continuation to the other request arguments. That design keeps the client independent of the backend’s internal representation. The token might encode a position, reference server-side state, or carry protected query details. Its appearance cannot prove which mechanism the service uses, and a client should not need that knowledge to continue correctly.Why Deterministic Ordering Matters
A deterministic order gives every record a defined position relative to the continuation boundary. Sorting by a non-unique timestamp can leave several records tied at the edge of a page. A typical keyset design adds an immutable unique identifier to the sort order, so the boundary refers to a complete ordering key. The exact choice depends on the database and the application’s data model.
Consider a hypothetical feed ordered by creation time and record ID. The next page begins after the final pair on the current page, using the same ordering direction. If several records share a creation time, the ID determines which ones have already been visited. This is a conceptual example rather than a description of a Scrapeless endpoint or a promise about a particular database execution plan.
The PostgreSQL ordering guidance explains why limited query results require a predictable order and why skipped offset rows still require server work. An appropriate index can support an efficient keyset lookup, but cursor pagination alone does not prove that index exists. Inspect the actual query plan when assessing a backend you operate; do not infer speed from the API’s parameter names.
Cursor, Offset, and Keyset Are Related Terms
Offset pagination identifies a position by how many rows to skip, while a cursor identifies a continuation boundary through the service’s token contract. Keyset pagination is a common database technique for implementing that boundary with ordered field values. An API may expose an opaque cursor while using a different internal method. Keep the public interface and the storage algorithm separate when evaluating performance claims.
Offset pagination can support familiar page-number navigation and direct jumps to a selected offset. Cursor traversal often prioritizes sequential continuation and may not support an arbitrary page jump. Neither interface automatically provides a cheap exact total. Product requirements such as jumping to page twenty, preserving a saved position, or browsing backward should be assessed against the documented API behavior rather than assumed.
| Feature | Offset | Cursor |
|---|---|---|
| Position | Skip amount or page number | Server-provided position or link |
| Direct jumps | Often supported within bounds | Only when the service supports them |
| Data changes | Positions may shift | Depends on order and consistency |
| Client state | Query and page position | Query and opaque cursor |
GraphQL Connections Define a Specific Contract
The GraphQL Cursor Connections Specification defines connection and edge structures, forward and backward pagination arguments, and page information. In that model, cursors belong to edges and page information describes whether more edges are available. Those field names are conventions of that specification, not mandatory names for every API that uses a cursor.
Forward traversal commonly uses a page size together with an after cursor; backward traversal uses the corresponding before boundary. The connection specification requires the edge order to remain consistent across those directions. A user moving backward should not receive an unexplained reversal of the collection’s business order. Implementations and clients need to agree on whether the display order and traversal direction are being discussed.
Use the documented end condition rather than estimating it from page length alone. Some APIs can return fewer items than requested while still providing continuation. Others define a final page through a missing token or a false continuation flag. A response with no visible records also needs careful interpretation: permissions, filtering, and the endpoint’s specific pagination behavior may influence what that page represents.
A Cursor Does Not Freeze a Changing Dataset
Cursor-based pagination does not automatically give all pages the same database snapshot. A service can evaluate each page against current data. New records may appear before the continuation boundary, existing records may be removed, and mutable sort fields can move a record across the boundary. Whether those changes cause omissions or repeated observations depends on the implementation and its consistency policy.
For a historical export, look for a documented snapshot, export job, or stable upper boundary. For a live feed, define whether the goal is to enumerate a fixed population or observe current entries. Those are different tasks. A high-water mark can help describe the capture scope, but it should only be used where the source supports the necessary ordering and filtering guarantees.
Keep record identities in the destination so repeated observations can be recognized. Deduplication can prevent duplicate rows, but it cannot prove that an unseen record was never skipped. Report coverage using the source’s explicit completion signal and the capture’s query boundary. A complete traversal of the interface and a complete historical inventory are not always equivalent statements.
Preserve Filters and Commit Checkpoints Carefully
A continuation token should travel with the query that produced it. Store a query fingerprint covering the collection, filters, sort order, and other relevant arguments. If the user changes the filter, begin a new traversal unless the service explicitly supports combining the old token with the new query. Treat an invalid token as a contract problem to investigate, not as evidence that the collection is empty.
Commit the page’s records before committing the next continuation state. The checkpoint should describe what has actually reached durable storage. Include the accepted record count, the last completed page identity where available, and whether the source reported more data. Keep sensitive token values out of shared logs; an opaque token can contain information even when the client is instructed not to inspect it.
Token lifetime also matters. A server-state token may expire, and a self-contained token may be bound to an authorization context or signing policy. Read the documented retention period before planning a long-running export. The SCIM cursor pagination standard demonstrates one specific standardized cursor contract, including continuation attributes; its rules should not be projected onto unrelated APIs.
Browser Interfaces Can Hide the Underlying Cursor
A load-more button or infinite-scroll list may use a cursor internally without exposing that cursor in the page URL. The visible interaction is the browser’s pagination interface, while network requests carry the data continuation. Begin with the behavior that the page and your authorization permit. Do not manufacture internal tokens or assume an undocumented endpoint is a stable public contract.
Scrapeless Agent Browser can provide the browser environment for an authorized result-navigation task. Use the Agent Browser concepts to understand that environment and the browser pagination patterns to distinguish visible navigation types. The collector still needs record identities, a bounded traversal scope, and a clear stopping condition.Review Scrapeless pricing when estimating session costs, but assess dataset quality independently from session duration. A hypothetical catalog capture might record each visible product ID after the page adds new cards and stop when the interface signals its end. That process can verify the observed browser traversal without claiming a transactional snapshot of the underlying catalog.
Choose Cursor Pagination for the Right Requirement
Cursor pagination is useful when sequential access to an ordered collection fits the product requirement. It can avoid the cost of large offsets in a suitable backend design and can express a stable continuation boundary more clearly than page numbers. It is less convenient when users require arbitrary page jumps or when a durable export must survive longer than the token’s lifetime.
Evaluate the query order, continuation contract, end marker, token lifetime, and consistency behavior together. Write those decisions into the consumer’s acceptance criteria before expanding collection. The quality of the final dataset depends on all of them. A correctly handled opaque token is one part of a reliable traversal, while authorization, storage, and coverage remain responsibilities of the surrounding application.
Conclusion
Treat a cursor as continuation state for one ordered query, preserve the service’s end conditions, and commit storage before advancing. Cursor pagination can support efficient sequential access, but a defensible dataset also needs a clear consistency boundary. Establish that boundary before calling a long traversal complete.
Build Your Web Data Workflow
Use Agent Browser for dynamic navigation while your collector records pagination state and verifies dataset coverage.
Sign up today and get $5 in free credit — no credit card required.
Claim Your $5 Credit →FAQ
Is cursor-based pagination the same as keyset pagination?
Cursor-based pagination is not necessarily identical to keyset pagination. A cursor is the API’s continuation interface, while keyset pagination is a database technique often used to implement it. The token can hide other backend mechanisms, so assess efficiency from implementation evidence rather than the interface alone.
Can a client decode an opaque cursor?
A client should treat an opaque cursor as an uninterpreted value. Even if its contents appear readable, decoding and constructing replacements creates a dependency on undocumented internals. Return the token exactly as the API documents and preserve the associated query settings.
Does cursor pagination prevent every duplicate or missing record?
Cursor pagination does not prevent every duplicate or missing record. Mutable data and per-request consistency can still affect traversal. Use deterministic ordering, documented snapshot boundaries where available, and record identities in storage, while reporting the capture’s actual consistency limits.
Can cursor pagination jump directly to any page?
Cursor pagination supports arbitrary page jumps only when the service provides that capability. Many cursor interfaces are designed for sequential traversal. A product that needs direct page selection should confirm the API’s navigation support before choosing its interface or promising that behavior.
What belongs in a pagination checkpoint?
A pagination checkpoint should include the committed continuation state and the query definition that produced it. Also record storage progress and the source’s completion signal. Advance the checkpoint only after accepted records are stored, and protect cursor values if they can expose sensitive query context.