Design Opaque Page Tokens for a Drive Files List API
Last updated: November 29, 2026
Quick Overview
Implement list pagination for a Drive-style files endpoint that returns stable results ordered by modified time while files are being created and edited, using an opaque next_page_token instead of offsets.
0
0
0 solved
Implement list pagination for a Drive-style files endpoint that returns stable results ordered by modified time while files are being created and edited, using an opaque next_page_token instead of offsets.
Google public APIs follow the AIP conventions, and list methods use page_token and page_size rather than offset. Interviewers use this to see whether you understand why offsets break under concurrent writes and how to make a cursor tamper resistant and tied to the original query.
What the Interviewer Expects
- Explain why offset pagination skips or duplicates rows under concurrent inserts
- Choose a unique, total sort key such as (modified_time, file_id)
- Encode the cursor opaquely and bind it to the query filter
- Validate page_size with a default and a maximum
- Return an empty next_page_token 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 do you handle a file whose modified_time changes while a client is paging?
- How would you sign the token so clients cannot forge positions?
- What happens if the client changes the filter but reuses the token?
- How would this work across a sharded backend?
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
list_files(files, page_size, page_token, query)returns(page, next_token).- Order newest first by
modified_time, ties broken byfile_idso the order is total. - Tokens are opaque strings; ...
High-Level Design
Offsets fail because an insert at the head shifts every later row by one, so the next page repeats an item; a delete makes the client skip one. A keyset cursor instead stores the last returned sort ke...