What is the difference between offset and cursor pagination in APIs?
Offset pagination says `page=3&limit=20` or `LIMIT 20 OFFSET 40` to skip N rows. It is easy but slow for deep pages on large tables, and if rows are inserted or deleted while users paginate, they can see duplicates or skips. Cursor pagination (keyset) uses an opaque token or `WHERE id > :cursor ORDER BY id LIMIT` so each page is anchored to a stable ordering key. Public APIs (Twitter, GraphQL cursor connections) often prefer cursors for infinite scroll. The trade-off is that jumping to an arbitrary 'page' is harder, and you must design stable sort keys.
-- offset styleSELECT * FROM posts ORDER BY created_at DESC LIMIT 20 OFFSET 100;-- cursor style (example)SELECT * FROM posts WHERE (created_at, id) < ($cursor_ts, $cursor_id) ORDER BY created_at DESC, id DESC LIMIT 20;Start simple: try this concept in a tiny project before moving to advanced tools.
apisqlperformance
Want to check this topic right now?
Check this question