Design a Paginated Order History API With Stable Cursors
Last updated: November 29, 2026
Quick Overview
Design and implement the endpoint that returns a customer's past orders newest first, with a status filter and pagination that never skips or repeats orders when new orders arrive between page loads.
DoorDash
November 29, 20260
0
0 solved
Design and implement the endpoint that returns a customer's past orders newest first, with a status filter and pagination that never skips or repeats orders when new orders arrive between page loads.
The Orders tab in the DoorDash app is read constantly and the list changes while a customer scrolls (a new order lands, an old one is cancelled). This API design question checks whether you choose keyset cursors over offsets, define a stable sort with a tie breaker, make cursors opaque and bound to their filters, and cap page sizes.
What the Interviewer Expects
- Explain why offset pagination skips or repeats rows when data changes
- Sort on a unique compound key: created_at descending, then order_id
- Return an opaque cursor encoding the last row served
- Bind the cursor to its filters and reject mismatches with a 400
- Clamp the limit and describe the backing index
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you support jumping to orders from a specific month?
- How would you paginate when results are merged from two services (restaurant orders and DashMart orders)?
- How would you version the cursor format without breaking old app versions?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
GET /v1/consumers/{id}/orders?limit=20&status=DELIVERED&cursor=....- Newest first; equal timestamps must still have a deterministic order.
- Response:
{orders: [...], next_cursor}with `next_cu...
High-Level Design
With OFFSET 20, a new order inserted at the top shifts everything down, so page two repeats the last order of page one; a deletion skips one. Keyset pagination instead says "give me rows strictly af...