pagination-design

Design offset, cursor, and keyset pagination strategies for large datasets with SQL and API implementations.

1|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill pagination-design-kalilurrahman
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pagination-design
Source: https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts/tree/main/01-software-dev/pagination-design
Command: npx skills add https://github.com/kalilurrahman/kr-claudiator-skills-original-prompts --skill pagination-design-kalilurrahman

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Offset pagination degrades to O(n) performance on large tables and produces inconsistent results when data changes between pages. This Skill helps you choose and implement the right pagination strategy—offset, cursor, or keyset—so APIs stay fast and stable at millions of records. ## Core Features & Use Cases - Strategy Selection: Compares offset, opaque cursor, and keyset (seek) pagination with performance, deep-linking, and complexity trade-offs. - Implementation Patterns: Provides SQLAlchemy/Python code for cursor encoding, bidirectional pagination, filtered pagination, and GraphQL Connections. - Performance Guidance: Covers composite indexes, avoiding COUNT(*) on large tables, and benchmark data for 1M-row datasets. - Use Case: You are building an orders API backed by a 5-million-row table. Use this Skill to implement keyset pagination with a composite index on (created_at, id), returning shareable URLs with O(log n) query performance. ## Quick Start Ask the AI to design cursor-based pagination for a large orders table sorted by created_at with a REST API response format.

Frequently Asked Questions about pagination-design

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement cursor-based pagination in a REST API?

Encode the last record's sort values (e.g., created_at and id) as base64 JSON and return it as next_cursor. On the next request, decode the cursor and filter rows with WHERE created_at < value, fetching limit + 1 records to determine has_next.

Offset vs cursor pagination: which should I use?

Use offset pagination only for tables under 10k rows where deep linking to page numbers matters. For tables over 100k rows, use cursor or keyset pagination, which run in O(log n) with proper indexes and avoid inconsistent results when data changes.

What is keyset pagination and when is it better than cursors?

Keyset pagination passes actual column values (like before_created_at and before_id) in the URL instead of an opaque token. It offers the same O(log n) performance as cursors but produces transparent, shareable, bookmarkable URLs.

Why is COUNT(*) slow with pagination on large tables?

COUNT(*) scans the entire table, becoming expensive at millions of rows. Alternatives include omitting total_count, using PostgreSQL's reltuples estimate from pg_class, or caching the count with a TTL.

Why does pagination return duplicate or skipped records?

Duplicates and skips happen when sorting by a non-unique column or when rows are inserted between page requests. Always add a unique tiebreaker column like id to the sort, and use cursor or keyset pagination instead of offset.

Does cursor pagination work with filters and GraphQL?

Yes. Apply filters before the cursor condition and create a composite index with filter columns first, then sort columns. For GraphQL, follow the Connections spec with edges, pageInfo, startCursor, and endCursor.