All Questions
Api Design medium

Your API lists 10 million orders. A client paginates with offset=5,000,000&limit=20. The database query is extremely slow. Why, and what's the fix?

  1. A Offset pagination requires the database to scan and discard millions of rows, leading to high CPU/IO. Use cursor-based pagination (keyset) to seek directly to a unique identifier.
  2. B The primary database instance is overloaded by the query complexity. Scale out by adding read replicas to handle the high volume of parallel offset-based scan operations.
  3. C The application layer is performing an O(N) filter operation on the full dataset before returning the page. Move the offset logic into a stored procedure for localized execution.
  4. D The database lacks a Bloom Filter on the primary key, causing every offset request to trigger a full table scan. Enable probabilistic indexing to quickly skip to the 5 millionth row.

One system design question a day, with spaced repetition so the ones you miss come back.

Get the app

Related questions