Cursor Pagination for Listing Fine-Tuning Jobs That Survives Inserts

Last updated: November 29, 2026

Quick Overview

Implement a list endpoint for fine-tuning jobs that returns newest first in pages, using an opaque cursor so pages stay correct when new jobs are created between requests. Explain why offset pagination is the wrong choice here.

OpenAI
Software Engineering Fundamentals
Software Engineer
OpenAI
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


Implement a list endpoint for fine-tuning jobs that returns newest first in pages, using an opaque cursor so pages stay correct when new jobs are created between requests. Explain why offset pagination is the wrong choice here.

OpenAI's public API lists objects like files, jobs, and messages with cursor parameters and a has_more flag. This question checks basic API design judgment: stable ordering, tie-breaking, opaque cursors, and limits.

What the Interviewer Expects
  • Explains how offsets skip or duplicate rows when data changes
  • Orders by a unique composite key such as created_at plus id
  • Fetches limit plus one to compute has_more without a count query
  • Makes the cursor opaque and validates it
  • Clamps the page size
Key Topics to Cover
API design
pagination
stable ordering
indexes
opaque tokens
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
  • What index would back this query in Postgres?
  • How would you support filtering by status without breaking cursors?
  • How would you paginate in both directions?
  • Should you sign the cursor, and why?
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

list_jobs(limit, after) returns up to limit jobs older than the cursor, newest first, plus has_more and next_cursor. Inserting new jobs while a client pages must not cause duplicates or skips....

High-Level Design

With OFFSET 20, a job created after page one shifts everything down by one, so the client sees the last item of page one again on page two. A keyset cursor instead says "give me rows strictly after ...


Submit Your Answer
Markdown supported