📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Why does offset pagination get slower on deep pages, and how does keyset pagination fix it in EF Core?

Mid-Level Coding Intermediate

🎯 Key points

  • OFFSET reads and discards skipped rows
  • Cost grows linearly with page depth
  • Keyset filters after the last seen key: index seek, constant cost
  • Needs a composite index matching ORDER BY and a unique tiebreaker
  • No random page access: fits infinite scroll, APIs, exports
  • Offset is still fine for shallow numbered pages

⏱ 30-second answer

Skip(n) becomes OFFSET n ROWS, so SQL Server reads and discards n rows every time; page 5,000 reads 100,000 rows to return 20, and cost grows linearly with depth. Keyset paging remembers the last row's sort key and filters WHERE Price > @lastPrice OR (Price = @lastPrice AND Id > @lastId) with the same ORDER BY Price, Id, which seeks an index and reads only the rows it returns, so every page costs the same. It is also stable when rows are inserted. The trade-off: no jumping to page N, so it suits infinite scroll, APIs and exports, while offset stays fine for shallow, numbered pages in admin screens. The sort key needs a matching index and a unique tiebreaker.

🔍 What the interviewer is checking

Checks paging performance awareness.

↩ Usually asked after

More in Querying

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me