All jobs / Backend developer / Performance
Backend developer interview question · 1–3 years
The interviewer asks: “Why is OFFSET 100000 slow even with a LIMIT 20?” Strongest answer?
The strongest answer
The database still walks and discards the first 100000 rows in the ordered index. Cost grows with the offset. A cursor on the last (sort key, id) seeks instead of skipping.
Why it works
Exactly. OFFSET is “skip N.” Deep pages scan N. Keyset pagination is O(log n) with the right index.
What a good answer covers
- OFFSET still reads the skipped rows.
- Deep pages want keyset/cursors.
- Index the (sort, id) tuple.
- Don't drop ORDER BY to “go faster.”
Answers that fall short
- Close, but not the strongest: LIMIT 20 always means 20 rows of work, so OFFSET can't matter.
The 20 is what you return, not what you examined. EXPLAIN will show the skip. - Weak: I need a bigger cache in the app.
Caching page 5000 doesn't fix the next user asking for page 5001. Fix the access path. - Red flag: Remove the ORDER BY so OFFSET can jump.
Unordered OFFSET is cheaper and wrong — rows shuffle between pages. Keep order; change the technique.
Who gets asked this
More Performance questions
- The interviewer asks: “Where do you enforce rate limits?” Strongest answer?
- The interviewer asks: “This query is slow in production but fine on your laptop. What do you do first?”…
- An endpoint takes 1.5 seconds at p95. The container’s CPU sits at 8% and the CPU profiler shows almost…
- The interviewer asks: “The cache expires and 2,000 requests hit the database at once. How do you prevent…
- Under load, someone raises the connection pool from 20 to 200 per instance. Throughput drops and p95 gets…
- The interviewer asks: “How do you know we can take 3× traffic on Monday?” Strongest answer?
- The interviewer asks: “The bill doubled but QPS didn't. Where do you look?” Strongest answer?
- A teammate opens a pull request that rewrites a service “for performance”. What do you ask for before you…