InterviewBuddy
All interview questions

What is the difference between pagination by offset and cursor?

Intermediate

Answer

Offset pagination skips a number of rows. Cursor pagination continues after a stable sort key from the previous page.

Explanation

Offsets are simple but can become slow and shift under concurrent inserts. Cursors work well for growing feeds when ordering is deterministic.

Example

ORDER BY created_at DESC, id DESC LIMIT 20