We're exposing a public REST API that returns a large, frequently-changing list of orders. How would you design the pagination, and why?

system-design · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate can reason about pagination trade-offs against the data shape — picking cursor/keyset over offset for a large, mutating dataset and understanding the database and correctness costs of each — rather than reflexively reaching for page/limit.

What to say

What to avoid

Example answers

Strong: Orders change constantly, so I'd use keyset pagination: sort by created_at with id as a tiebreaker, and the cursor is an opaque base64 token encoding the last (created_at, id) seen. The next page is WHERE (created_at, id) < (:ts, :id) ORDER BY created_at DESC, id DESC LIMIT n, which uses the index and costs the same on page 1 or page 1000 — no scanning rows I throw away. The cost is I can't jump to an arbitrary page, but for a feed-style order list nobody does that. I'd return a next_cursor field and stop returning it when there's no more data.

Weak: I'd add page and page_size query params and use LIMIT and OFFSET, and return the total count so the client can render page numbers.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.