How do you design pagination, filtering and sorting for a list endpoint?
Reviewed by Gurusankar M.
Short Answer
Support filtering via query params, sorting via ?sort=field,-field, and pagination via cursor (?cursor=...&limit=) for large/real-time data or page/size for small admin lists. Always cap the page size, return total/next-cursor metadata, and keep results stably ordered.
On this page
Concept Made Simple
Coffee Chat Question
“How do you design pagination, filtering and sorting for a list endpoint?”
Remember It Faster
Mind Map Answer
- Filter
- ?status=open&created_after=...
- Sort
- ?sort=-created_at,id
- Paginate
- cursor for scale; page/size for small sets
- Always
- cap limit, stable order, next-cursor meta
Think Beyond the Expected
What If?
Why prefer cursor pagination over page/offset for a large, frequently-changing list?
Offset gets slower the deeper you page and can skip/duplicate rows when items are inserted/deleted between requests. A cursor (keyset) seeks via an indexed key — constant time and stable under concurrent changes. (Same reason as DB keyset pagination.)
Real World
Public list endpoints expose opaque `next` cursors and capped limits; uncapped page sizes and offset pagination are common causes of API DoS and slow deep pages.
Interviewer's Expectation
Keywords they're listening for:
- query-based filter/sort
- cursor vs offset
- cap page size
- return pagination metadata
- stable ordering
Common Mistakes
- Uncapped page sizes (DoS risk)
- Offset pagination on huge/live lists
- Unstable sort breaking cursors
Best Practices
- Cap and default the limit
- Use cursor pagination at scale
- Return next-cursor + (optional) total
Follow-up Questions
- How do you make a cursor opaque and stable?
- How do you prevent clients requesting limit=1000000?
- How does sort interact with cursor stability?
Continue Learning with AI
Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.
Plain-language foundations
I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner. Topic: Versioning (REST APIs) Interview question: "How do you design pagination, filtering and sorting for a list endpoint?" Please: 1. Explain the core idea in simple, plain language, using an everyday analogy. 2. Define any technical terms you use. 3. Walk through one small, concrete example. 4. Finish with a single sentence I can easily remember. Keep the tone friendly and assume I'm new to this topic.
Was this answer helpful?
Affiliate links
Tools for Your Developer Workspace
Equipment for a comfortable, productive setup.
As an Amazon Associate I earn from qualifying purchases.
- MonitorView on Amazon : BenQ EW2790U 27-inch Monitor (opens in a new tab)
BenQ EW2790U 27-inch Monitor
- LaptopView on Amazon : Acer Aspire One Laptop (opens in a new tab)
Acer Aspire One Laptop
- Office ChairView on Amazon : Wakefit Gravita Ergonomic Office Chair (opens in a new tab)
Wakefit Gravita Ergonomic Office Chair