Networking and APIs / Beginner / 5 min / Updated
API pagination: offset vs cursor (keyset)
Page through 10 million rows. Deep offsets read a million rows for 20 results and repeat items when new rows arrive; cursors stay fast and exact.
Start the simulation → Change the load, break a part, watch what happens. Free, no sign-up.
In short
What is API pagination?
Offset pagination skips N rows with LIMIT/OFFSET; cursor pagination continues after the last id seen.
Why does it matter?
Any list that can grow (feeds, orders, search results) must be returned a page at a time.
What is the trade-off?
Offset allows page jumps but slows down deep and repeats or skips items on change; cursors are fast and exact.
How do you explain it in an interview?
"Cursor-based with an opaque next_cursor encoding (created_at, id); offset only for small admin tables."
Check yourself
Why does OFFSET 1000000 get slow?
Answer: The database must walk past a million rows before returning 20. OFFSET skips by reading; the work grows with the page number.
A new post arrives while a user reads page 1 of a newest-first feed. What happens on page 2 with offset paging?
Answer: The last item of page 1 appears again at the top of page 2. Everything shifted down one place, so offset 20 now starts one item earlier.
What does a cursor (keyset) give up?
Answer: Jumping straight to an arbitrary page number. You can only go to the next (or previous) page from where you are.