
Pagination with Claude Code: Cursor-Based vs OFFSET and Infinite Scroll
OFFSET pagination breaks on tables with millions of rows — each page requires scanning all previous rows. Cursor-based pagination stays fast at any scale. Claude Code generates the complete implementation. CLAUDE.md for Pagination Rules ## Pagination Design Rules ### Method - Over 10,000 rows: cursor-based required (OFFSET forbidden) - Admin UIs with small datasets: OFFSET pagination acceptable - Infinite scroll: cursor-based + hasNextPage ### Cursor-Based - Cursor must be opaque (don't expose internal structure to clients) - Encode cursor as Base64 of ID or composite key - Response includes nextCursor and hasNextPage ### Performance - Enforce pageSize limit (max 100) - orderBy required (needed for cursor-based sorting) - Index cursor column Generating Cursor Pagination Generate cursor-based pagination API. Endpoint: GET /api/users Parameters: cursor?, limit(1-100, default 20) Response: { data: User[], nextCursor: string | null, hasNextPage: boolean } Requirements: - Prisma cursor pagi
Continue reading on Dev.to
Opens in a new tab




