Design Cursor Pagination for a List Charges API Endpoint
Last updated: November 29, 2026
Quick Overview
Implement the list operation behind GET /v1/charges, returning charges newest first with limit, starting_after, and ending_before cursors plus a has_more flag, so clients can page reliably while new charges keep arriving.
Stripe
November 29, 20260
0
0 solved
Implement the list operation behind GET /v1/charges, returning charges newest first with limit, starting_after, and ending_before cursors plus a has_more flag, so clients can page reliably while new charges keep arriving.
Every Stripe list endpoint uses object-id cursors rather than page numbers, and API design questions in Stripe screens often start with exactly this shape. The interviewer checks whether you understand why offsets break under concurrent inserts, how to order deterministically with ties, and how to validate parameters.
What the Interviewer Expects
- Explains why offset pagination skips or repeats rows when new charges are inserted
- Orders by a unique, stable key (created timestamp plus id as a tiebreaker)
- Implements starting_after and ending_before correctly, including has_more
- Validates limit bounds and rejects passing both cursors
- Describes the equivalent SQL keyset query and the index it needs
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
- What SQL query and index would serve this at Stripe scale?
- How would you add a created[gte] filter without breaking cursors?
- Should cursors be raw object ids or opaque encoded tokens, and why?
- How would you build an auto-paginating iterator in a client library on top of this?
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
- Newest first.
limit1 to 100, default 10. starting_after=<id>returns the page after that object;ending_before=<id>the page before it.- Response:
{"data": [...], "has_more": bool}. - A ...
High-Level Design
Offsets fail because inserting one charge at the head moves every later row down by one, so page 2 repeats an item. A cursor anchors on an object instead: "everything strictly older than ch_123". Ti...