Why pages exist
No endpoint should return a million rows in one response. Pagination breaks a list into pages. The two dominant styles differ in how they remember where you left off.
Offset pagination
Offset uses a limit and a skip count, like give me twenty rows after skipping forty. It is trivial to implement and lets you jump to any page. Its weaknesses appear at scale.
- Deep offsets are slow because the database still scans the skipped rows.
- If rows are inserted or deleted while paging, you can skip or repeat items.
Cursor pagination
Cursor pagination remembers a stable pointer, usually an encoded id or timestamp of the last item seen. The next page asks for rows after that cursor.
- It stays fast at any depth because it seeks directly.
- It is stable under inserts and deletes since it anchors on a value, not a position.
- The cost is that you cannot jump to an arbitrary page number.
Key idea
Offset is simple but breaks at depth and under churn, while cursors stay fast and stable by anchoring on a value.