← Lessons

quiz vs the machine

Gold1450

System Design

Pagination Patterns Cursor and Offset

Returning large lists in pages without missing or duplicating rows under churn.

5 min read · core · beat Gold to climb

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.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does deep offset pagination get slow?

2. What makes cursor pagination stable under inserts and deletes?

3. What does cursor pagination give up compared to offset?