Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Several public APIs in your company use OFFSET pagination and large partners now page through millions of records nightly, causing database load. How would you migrate them without breaking partners?

I would add cursor pagination alongside the existing parameters, keep OFFSET working but cap the maximum offset and document the limit, and give partners who really need full syncs a bulk export or a change feed, because paging through millions of records is the wrong tool for that job. The migration is driven by data: measure usage per partner, help the largest ones move first, and announce a deprecation timeline, with rate limits and caps protecting the database meanwhile. Cursor pagination then becomes the default in our API guidelines and shared libraries so the problem does not return.

Why this question is asked

Public APIs are contracts: partners have built systems on them, and breaking them costs trust and sometimes money. At the same time, OFFSET pagination used for nightly full syncs can put a database under heavy load every night, and it gets worse as data grows. A senior engineer has to fix the load without breaking anyone, and that is mostly a plan of communication and sequencing on top of a simple technical change. Interviewers ask this to see that balance. In this answer, we will see why the nightly paging hurts, add cursors without breaking anything, cap offsets, offer the right tool for full syncs, run the migration with data, and make the fix permanent.

1Why Nightly Paging Hurts So Much

A partner that downloads 5 million records with 100 per page sends 50,000 requests. With OFFSET, request number n makes the database read and discard n x 100 rows before returning 100. Summed over the whole sync, that is about 50,000 x 50,000 / 2 x 100, more than 100 billion row reads for 5 million useful rows. The work grows with the square of the data size, so when the partner's data doubles, the nightly load roughly quadruples. A few large partners doing this at the same time explains the database load, and it also gives them incorrect data, because rows inserted or deleted during the sync shift pages and cause duplicates or gaps.

2Add Cursors Without Breaking Anyone

The first change is additive. Every list endpoint accepts a new cursor parameter and returns a next cursor in each response, using keyset pagination on a unique, indexed order such as (updated_at, id). Existing clients that send page and offset keep working exactly as before. Nothing is removed, so nobody breaks, and partners can switch at their own pace.

Java
GET /v2/customers?limit=500 -> { items: [...], next: "c2Vla..." }
GET /v2/customers?limit=500&cursor=c2Vla... -> next 500, each request one index seek
GET /v2/customers?limit=100&offset=250000 -> still works, unchanged for now

The cursor is opaque, an encoded and signed position, so we can evolve it. Because each cursor request is an index seek plus one page, a 5 million record sync costs about 5 million row reads instead of 100 billion.

3Cap Offsets and Protect the Database

Next we cap the maximum offset, for example at 10,000 rows, and document it. Interactive users essentially never page that deep; requests beyond it are syncs, which should use cursors or exports. The cap is introduced with a notice period, and requests beyond it return a clear error explaining what to use instead.

During the transition, rate limits per partner protect the database: a maximum request rate, and if needed lower limits on deep offset requests specifically. Deep paging can also be routed to a read replica so the primary stays safe. These are temporary guards; the real fix is the migration.

4Offer the Right Tool for Full Syncs

A partner who pages through millions of records every night does not really want pages; they want a copy of their data and its changes. Two better tools exist. A bulk export produces a file, such as compressed JSON lines or Parquet in object storage, generated once from a replica or a snapshot and downloaded in one go. A change feed lets them sync incrementally: give me everything that changed since my last checkpoint, which is usually a tiny fraction of the full set, driven by updated_at with a cursor or by events from change data capture.

With a change feed, the nightly 5 million record download becomes perhaps 40,000 changed records, which is better for the partner too: faster, cheaper and correct.

Matching the access pattern to the tool
Partner needRight toolDatabase cost
Browse or show a listcursor paginationone seek per page
Full copy, occasionallybulk export fileone scan on a replica
Stay in sync every nightchange feed since checkpointonly changed rows
Legacy client, shallow pagesOFFSET up to the capsmall, bounded

5Run the Migration With Data

We start by measuring: which partners make deep offset requests, how many, at what times, and how much database time they cost. This usually shows that a handful of partners cause most of the load. Those get personal help first: a technical contact, sample code, maybe a test environment, because moving three partners may remove 80% of the problem. Everyone else gets a deprecation timeline announced well in advance, for example six or twelve months, with reminders and a dashboard or response header telling them they are using a deprecated pattern.

Throughout, we track the share of sync traffic on cursors or exports and the database load during the nightly window, and we only enforce the offset cap once the large partners have moved.

Step throughMigration plan
  1. Add cursors and exportsadditive, nothing breaks
  2. Measure deep-offset usage per partnerfind the few that cause most load
  3. Help the largest partners migratecontact, samples, test environment
  4. Announce deprecation timelineheaders, docs, reminders
  5. Large partners moved?
    YesEnforce offset capNoKeep rate limits, extend support

5 steps in order. Play them, or step through them one at a time.

6Make It the Default

Finally, we prevent the next API from repeating the problem. The API guidelines say that list endpoints use cursor pagination by default, with offsets only for small bounded lists. The shared libraries that services use to build endpoints provide cursor encoding, signing and the keyset query helpers, so the right thing is also the easiest. API review checks new list endpoints for it. That turns one migration into a lasting change.

7Follow-up questions

What if a partner cannot change their client for a year?

We keep their existing behaviour working within limits: OFFSET up to the cap, rate-limited, perhaps served from a replica, and if their sync really needs deep pages, a temporary exception for that partner with an agreed end date. Offering a bulk export that their existing tooling can download is often easier for them than changing pagination code.

How do you keep the change feed correct?

Using updated_at alone can miss rows when several transactions commit out of order with close timestamps, so the feed should use a cursor of (updated_at, id) with a small overlap window, or better, events from change data capture with an increasing sequence number. Deleted records must also appear in the feed as tombstones, or partners never learn about deletions.

How do you know the migration succeeded?

Database load during the nightly window falls, deep offset requests trend to zero, the share of sync traffic using cursors, exports or the change feed rises, and partner support tickets about duplicates or missing records drop.

8Conclusion

In this answer, we migrated public APIs away from OFFSET without breaking partners. We added cursor pagination alongside the old parameters, capped the maximum offset with notice and protected the database with rate limits, and offered bulk exports and a change feed to partners who need full syncs. We measured usage per partner, helped the largest move first, announced a deprecation timeline, and made cursor pagination the default in guidelines and shared libraries.

What to say in the interviewAbout 90 seconds aloud

Open with

I would treat it as an additive migration, not a breaking change. First, add cursor pagination to every list endpoint next to the existing parameters: a cursor parameter in, a next cursor out, backed by keyset queries on something like updated_at and id.

Then, if they want more

OFFSET keeps working, so nobody breaks. Second, look at what the large partners actually do. Paging through millions of records every night is really a sync, and with OFFSET its cost grows with the square of the data.

So I would offer the right tools: a bulk export file generated from a replica, and a change feed that returns only what changed since their last checkpoint, which for most partners is a tiny fraction of the full set. Third, drive the migration with data.

Measure deep offset usage per partner, usually a handful cause most of the load, and help those first with a contact, samples and a test environment. Everyone else gets a clear deprecation timeline, documentation, and a response header telling them they use a deprecated pattern. Meanwhile, rate limits and routing deep pages to a replica protect the database.

Once the large partners have moved, I enforce a documented maximum offset, for example 10,000, with a clear error that points to cursors and exports. Finally, I make cursor pagination the default in our API guidelines and in the shared library services use, so new APIs never start with this problem.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Several public APIs in your company use OFFSET pagination and large partners now page...": https://scrivio-interview-library.netlify.app/databases/query-optimization/97e405e9af/