Keyset pagination is a paging method that uses the last seen sort values to fetch the next page of results. It avoids OFFSET scanning by comparing rows against a cursor condition, usually on an ordered and indexed column set, so pages stay stable as data changes.
How Keyset Pagination Works
Keyset pagination advances through a result set by using the last row from the previous page as the starting point for the next page. Instead of counting or skipping rows, the query reuses the ordered key values to continue from a known position, which keeps the paging logic aligned to the data’s sort order.
This approach is usually built on an indexed column, or a small ordered set of columns, so the database can seek directly to the next boundary. That makes it a strong fit for large tables, append-heavy datasets and user interfaces where the order must remain consistent as rows are inserted or updated.
Why It Is Preferred Over OFFSET Pagination
OFFSET-based paging becomes more expensive as page numbers increase because the database must walk past earlier rows before returning the requested slice. Keyset pagination avoids that scanning cost, so performance tends to degrade much less sharply when users move deeper into a dataset.
It is also more stable under change. If new rows arrive or existing rows move within the sort order, OFFSET pagination can duplicate or skip records between pages. Keyset pagination reduces that drift because each request resumes from a concrete sort boundary rather than from a shifting row count.
Query Conditions and Ordering Rules
The keyset condition must match the sort order exactly, including tie-breakers when the leading sort column is not unique. In practice, that means the pagination predicate must compare the next rows against the last seen values in a deterministic order, otherwise records can be repeated or omitted.
Good keyset design depends on predictable ordering. If the sort column can change frequently, or if the chosen order does not reflect the user’s real browsing pattern, the page sequence may still feel inconsistent even when the paging mechanism is technically correct. The method works best when the order is business-relevant and naturally indexed.
Where Keyset Pagination Fits Best
Keyset pagination is most useful when the result set is large, the sort order is well defined, and users are browsing forward through recent or ordered data. It is a common fit for activity feeds, event logs, transactional lists and any interface where fast next-page retrieval matters more than jumping to an arbitrary page number.
It is less suitable when the product requirement is direct random access to page 47, because keyset pagination is stateful by design. The page boundary is derived from the last returned record, so the method favors sequential navigation over absolute page indexing.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
NIST SP 800-53 Rev 5, CIS Controls v8, NIST CSF 2.0 and OWASP ASVS set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | AU-11 — Audit Record Retention | Stable ordered retrieval supports auditable review of record sequences. |
| AC-6 — Least Privilege | Efficient cursor-based access patterns support constrained, need-to-know data retrieval. | |
| Recommendation — Retain query and result records long enough to investigate paging anomalies and sequence-related access disputes. Limit query scope and returned columns to the minimum needed for the page view. | ||
| CIS Controls v8 | CIS-8 — Audit Log Management | Paging stability matters for reliable review of data access and result-set traversal. |
| Recommendation — Log pagination requests and boundary parameters so investigators can reconstruct data access paths. | ||
| NIST CSF 2.0 | PR.AA-01 — Identity Management, Authentication, and Access Control | Pagination controls data exposure and should respect access boundaries on ordered result sets. |
| Recommendation — Enforce access rules consistently on every page request and continuation token. | ||
| OWASP ASVS | V8 — Authorization | Page-by-page retrieval must preserve authorization decisions across repeated result fetches. |
| Recommendation — Recheck authorization for each continuation request and each returned object. | ||
Related resources from NHI Mgmt Group
- How should security teams implement cursor based pagination in SCIM when directory syncs get large?
- What breaks when pagination is flattened into a single MCP tool call instead of being designed explicitly?
- Why do enterprise admin consoles need pagination at scale?
- When is cursor-based pagination a better choice than page-number pagination for infinite scroll?
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on November 25, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org