MediumπŸ‘€ 3-5 yearsπŸ‘€ 8-15 years 1 min read

How do you design pagination, filtering and sorting for a list endpoint?

Asked inAmazonGoogleMicrosoft
#pagination#filtering#sorting#cursor#api design
Report issue

⚑ 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

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

πŸ”₯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:

βœ“ 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

  • 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

cursor paginationkeyset paginationOpenAPI

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?

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.

Related Questions