awesome-everything RU
↑ Back to the climb

APIs

Pagination: multiple-choice review

Crux Multiple-choice synthesis across the pagination unit: offset-vs-keyset cost, page drift under writes, stable ordering, opaque cursors, and the hidden count tax.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that span the whole unit. None is a definition to recite — each is a call you make designing a real list endpoint that has to survive a 50-million-row table and constant writes.

Goal

Confirm you can connect offset cost, page drift, ordering stability, the opaque-cursor contract, and the count tax — the synthesis the lesson built toward, not the individual facts.

Quiz

An endpoint serves LIMIT 20 OFFSET 200000 against a 50M-row table. It returns 20 rows but takes ~8 seconds. Why does cost grow with the offset and not the page size?

Quiz

On a fast-moving feed, users report seeing the same post twice and others swear posts 'disappeared.' The frontend is correct and the table is small. What is the cause?

Quiz

A keyset feed orders by created_at DESC only and carries the last created_at forward as the cursor. Occasionally a post is skipped or shown twice at a page seam. Why, and what fixes it?

Quiz

A product needs an admin table with 'jump to page 4,000 of 80,000' AND a public infinite-scroll feed over the same data. What is the right call?

Quiz

A teammate proposes returning the raw (created_at, id) tuple as the cursor 'since the client just echoes it back anyway.' Why prefer an opaque encoded cursor?

Quiz

The endpoint is now fast via keyset, but p99 is still high because of the 'Showing 1–20 of 4,812,339' footer. Why is the exact count expensive in Postgres, and what is the senior move?

Recap

The unit’s through-line is one decision: address pages by position (offset) and you pay twice — deep pages scan-and-discard linearly, and positional boundaries drift under writes into duplicates and skips. Address them by value (keyset) over a unique, stable, indexed key and latency stays flat with no drift, at the cost of losing arbitrary page jumps — which is why offset still earns its place on bounded admin tables. Hand clients an opaque cursor so the contract can evolve, and treat the exact total as its own scan: estimate or probe with LIMIT n+1 instead of paying for a count nobody needs.

Continue the climb ↑Pagination: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.