How do you design pagination, filtering and sorting for a list endpoint?
β‘ 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.
βCoffee Chat Question
Concept Made Simple
βHow do you design pagination, filtering and sorting for a list endpoint?β
π§ Mind Map Answer
Remember It Faster
π₯What If?
Think Beyond the Expected
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:
β οΈ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
- 1How do you make a cursor opaque and stable?
- 2How do you prevent clients requesting limit=1000000?
- 3How does sort interact with cursor stability?
π§©Related Technologies
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?
β Featured Products
Support our platform by exploring our recommended products.
As an Amazon affiliate, purchases through these links may earn us a small commission β at no extra cost to you. It helps keep Full Stack Interview Guru free.