[Full-Stack Development]PUBLISHED 2026-11-25//4 min read//VERIFIED 2026-11-25

Stable Cursor Pagination for APIs with Mutable Datasets

Use deterministic ordering and an opaque continuation cursor to page through changing collections predictably.

EXECUTIVE ARCHITECTURAL OVERVIEW

Cursor pagination resumes a query after a known ordered position instead of skipping a numeric offset. With a stable ordering and matching index, it avoids scanning an ever-growing offset and is less sensitive to rows inserted before the current page.

THE PRODUCTION PROBLEM STATEMENT

Offset pagination can become slower for deep pages and can repeat or skip rows as the dataset changes between requests. A timestamp alone is also not a unique cursor when multiple records share that value.

SECTION 01 //

Define a deterministic order with a unique tie-breaker

Choose a stable order and include a unique tie-breaker. For descending creation time, ordering by created_at and then id gives every row a defined position. The cursor must carry both values so the next query resumes after that pair.

Add an index that matches the filter and ordering pattern. Keyset pagination can then seek from the cursor instead of counting through all earlier rows.

list-events.sql
SELECT id, created_at, event_type
FROM events
WHERE account_id = $1
  AND (created_at, id) < ($2, $3)
ORDER BY created_at DESC, id DESC
LIMIT $4;
The tuple comparison follows the same descending order used by the result set.
SECTION 02 //

Encode cursors as an API contract, not SQL input

A cursor can encode ordered fields and a version marker, then be base64url-encoded for transport. Encoding is not encryption and does not make the value trustworthy. Validate its shape and bind decoded fields as query parameters.

If clients must not alter cursors, sign the payload with an integrity key. Keep filters and sort direction tied to the cursor contract so it cannot be replayed against an unrelated query.

cursor-payload.json
{
  "v": 1,
  "createdAt": "2026-11-25T08:20:00Z",
  "id": "evt_01J..."
}
A versioned payload can be encoded and optionally signed by the server.
SECTION 03 //

Explain consistency under concurrent writes

Keyset pagination is stable relative to ordered keys, but it is not automatically a database snapshot across separate HTTP requests. New rows may appear before the current cursor, and edits to ordering fields can move rows across pages.

For a frozen export, create a snapshot or use a consistent high-water mark and immutable sort keys. For an activity feed, it is reasonable for new records to appear on refresh; document that behavior.

TECHNICAL INQUIRY MATRIX

Frequently Asked Questions & Technical Inquiries

Direct, practical answers to common architectural and debugging questions.

No. Encoding alone is not encryption or integrity protection. Validate the shape and sign the value if alteration matters.

Official References & Specifications:
Faisal Askari

Faisal Askari

Verified Author

Software Engineer & Full-Stack Developer

Personal Website

Faisal Askari is a software engineer with deep expertise in web systems architecture, the JavaScript runtime ecosystem, and client-side performance engineering. Over years of hands-on production engineering, he has designed and shipped enterprise dashboards, high-converting digital interfaces, and specialized full-stack applications.

SPEC // VERIFIED ENTITY•Karachi, Pakistan (Global Remote)
contact@faisalaskari.top
05/RELATED ENGINEERING GUIDES
CONTINUE STUDY