Design Cursor-Based Pagination for the Your Orders History API
Last updated: November 29, 2026
Quick Overview
Design and implement a paginated endpoint that lists a customer's orders newest first, returning opaque cursors that stay correct when new orders arrive between page requests.
Amazon
November 29, 20260
0
0 solved
Design and implement a paginated endpoint that lists a customer's orders newest first, returning opaque cursors that stay correct when new orders arrive between page requests.
The Your Orders page serves customers with anywhere from a handful to tens of thousands of orders, and offset pagination both skips rows when new orders land and scans deep pages slowly. The interviewer checks keyset pagination, tie-breaking, cursor opacity, and server-side limits.
What the Interviewer Expects
- Explains why offset pagination duplicates or skips rows and gets slow on deep pages
- Uses a keyset cursor over a unique, stable sort key with a tie-breaker
- Makes the cursor opaque and tamper-evident
- Caps the page size on the server
- Returns no next cursor on the last page
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 filtering by year without breaking cursor validity?
- What happens to a cursor if the sort key of a row changes?
- How would you support jumping to an arbitrary page number if product insists?
- How does this map to DynamoDB's LastEvaluatedKey?
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 /orders?limit=&cursor=returns orders sorted by placement time descending.- Orders placed after page 1 was fetched must not shift later pages.
- Clients must not depend on cursor format.
- Pa...
High-Level Design
Sort by (placed_at desc, order_id asc); the order id breaks ties when many orders share a timestamp. The cursor encodes the last row's sort key, signed with an HMAC and base64 encoded so clients tre...