Menu

Offset vs Cursor Pagination: Why Your API Breaks at Scale
📰

Offset vs Cursor Pagination: Why Your API Breaks at Scale

DEV Community: sql·tanmay kuamr chaurasia·about 18 hours ago
#uaVh59md
#devtosql#devto#dev#pagination#cursor
Long article (899 words) — no AI summary yet.
Reading 0:00
15s threshold

Most APIs start with offset-based pagination. It feels natural: GET /items?page=500&limit=20 is easy to understand, easy to build, and works seamlessly when your database tables contain a few thousand records.

However, once your database table grows to hundreds of thousands or millions of rows, offset pagination quietly degrades performance and causes subtle data anomalies that frustrate end users.

Here is why offset pagination fails at scale and how cursor-based pagination fixes it.

The Hidden Cost of OFFSET

To understand why offset pagination slows down, look at what the database engine does under the hood when executing an OFFSET query.

SELECT id , title , created_at FROM articles ORDER BY created_at DESC LIMIT 20 OFFSET 100000 ;

Enter fullscreen mode

Exit fullscreen mode

When you request OFFSET 100000 , the database does not magically jump to row 100,001.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.