- All Courses
- API Design with Node.js
- Building the Service
- Pagination, filtering, and sorting
Pagination, filtering, and sorting
An endpoint returning all records works in development and falls over in production.
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
Notes are not saved yet — they clear when you leave this page.
Error handling and problem details
9m
Authentication with tokens
24m