Lesson 2.4

Pagination, filtering, and sorting

An endpoint returning all records works in development and falls over in production.

3mBeginner15.4k students

Overview

Every collection grows

An endpoint returning all records works in development and falls over in production. Paginate from the first version, with a default page size and a hard maximum, because clients will ask for a hundred thousand rows if you let them.

Offset pagination skips and duplicates rows when data changes between pages. Cursor pagination keyed on a stable sort column stays correct, and it stays fast at any depth.

Expose a fixed set of sortable fields and filters. Arbitrary sorting means arbitrary queries, and an unindexed sort column is a table scan per request.

In this lesson you will:

  • Always paginate collection endpoints
  • Prefer cursors for changing data
  • Constrain filter and sort options

Resources

Previous Lesson
Next Lesson
Pagination, filtering, and sorting — API Design with Node.js — Vertex