Skip to main content

Replace Offset With Cursor Pagination

Design cursor pagination that preserves stable ordering as records are inserted or deleted.

backend-development5 min read

GET /payouts?offset=200&limit=50 duplicates and skips rows when new payouts are inserted while an admin is paging through failures. Use deterministic ordering plus opaque continuation tokens instead of client-computed offsets. Offset pagination works in demos because fixtures do not move. In production, inserts and deletes shift row positions between requests, so page numbers describe a moving target. Choose order Sort by created_at desc, id desc so records with equal timestamps still have a deterministic position. A cursor needs a total order, not just a friendly display sort. Fetch boundary Request limit + 1 rows after the decoded cursor boundary. The extra…

Read the full lesson

Sign up free: one personalized lesson every day, matched to your role and goals.

← Back to library

Contact us