API Fundamentals Course
API Fundamentals
/
Intermediate

Pagination

Definition

The process of dividing a massive dataset into smaller, discrete chunks (pages) when returning it via an API, to prevent crashing the server and overloading the network.

Explain Like I'm New

If Amazon has 5 million pairs of shoes, `GET /shoes` cannot return all 5 million at once. Your browser would crash, and Amazon's server would melt. Instead, they return 20 shoes at a time, and tell you how to ask for the next 20.

Real World Example

Offset Pagination (Page 1, 2, 3) used on Google Search results. Cursor Pagination (Infinite Scroll) used on Instagram's feed.

Common Use Cases

  • •Large datasets
  • •Mobile bandwidth optimization

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What are the two most common query parameters used to implement Offset Pagination?

intermediate

  • Why is Cursor Pagination preferred over Offset Pagination for infinite-scrolling social media feeds?

Flash Cards

Question

Which query params?

Click to reveal answer
Answer

`page` and `limit` (e.g., `?page=2&limit=50`), or `offset` and `limit`.

Question

Why Cursor over Offset?

Click to reveal answer
Answer

If you use `page=2` while people are actively posting new tweets, the entire list shifts downward. When you load Page 2, you will accidentally see tweets you already saw on Page 1. Cursor pagination solves this by saying 'Give me 10 tweets immediately *older* than Tweet ID 99', which is always perfectly accurate regardless of new posts.