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
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Software Engineering Fundamentals
Medium

0

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
API design
keyset pagination
opaque cursors
HMAC
sort stability
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported