Card 08/ 08

RecapDifficulty: Intermediate1 min

Recap: API Pagination

Two strategies, the two ways offsets fail, and which to choose.

  • Every list needs a limit, a stable order and a next page (Returning a Large Result a Page at a Time).
  • Offsets count rows to skip: page n is (n − 1) × limit, and any page can be reached directly (Offset Pagination Example: limit=25 and offset=100).
  • Cursors point at the last row seen, and seek past it through an index (Cursor Pagination Example: Every Order After id 4180).
  • Page numbers and still data mean offsets; scrolling and changing data mean cursors (Offset vs Cursor Pagination).
  • Inserts and deletes shift offsets, repeating or skipping rows (Offset Pagination That Skips or Repeats Rows).
  • Deep offsets read every row they skip, so their cost grows with the page number (Deep Offsets That Slow Every Page).