⚡ API Pagination Performance

Interactive deep-dive: Offset vs Cursor vs Keyset vs Seek
100,000
50
30 ms
10 ms
50
⚙️ DB read cost: $0.10 / million reads

📊 Performance & cost comparison

🔁 Offset total time
-
all pages
⏩ Cursor total time
-
all pages
⏩ Keyset total time
-
all pages
⏩ Seek total time
-
all pages
StrategyTime to page NDB reads cost
Offset--
Cursor--
Keyset--
Seek--

🧠 Recommendation matrix

📌 Small dataset + few pages

Offset is fine. Simplicity wins. Cursor adds complexity without benefit.

📌 Large dataset + random access

Cursor / Keyset. Avoid offset deep pagination. Use indexed cursor.

📌 Large dataset + sequential

Seek / Keyset optimal. Constant time per page, ideal for infinite scroll.

📘 Implementation guide: Cursor pagination (SQL + REST)

SQL (cursor-based)

-- Cursor: WHERE id > ? ORDER BY id LIMIT ? SELECT * FROM items WHERE id > :last_seen_id ORDER BY id ASC LIMIT :page_size;

REST API response format

{ "data": [ ... ], "pagination": { "cursor": "eyJpZCI6IDF9", "has_more": true, "next_cursor": "eyJpZCI6IDUwfQ==" } }

💡 Keyset/Seek use same principle: WHERE indexed_col > value. Offset degrades because of OFFSET + LIMIT scanning.

Recommended by our team

BeLikeNative.com

The #1 AI writing tool for freelancers — perfect grammar in any language, instantly.