Offset pagination works fine until your table grows. Then page 40 gets slower than page 1, and rows start appearing twice or disappearing between pages. If your Laravel API lists anything that keeps growing, claims, orders, events, log rows, cursor pagination is the fix. It is built into Laravel, it costs almost nothing to adopt, and it removes a whole class of bugs that offset pagination cannot avoid.
Why offset pagination breaks on large tables
When you ask for OFFSET 10000 LIMIT 15, PostgreSQL still has to find and discard the first 10,000 rows. The deeper the page, the more work the database does for the same 15 rows. On a table with a million rows, the last pages crawl while the first page is instant. I have seen this show up as a slow endpoint that only some users report, because only they scroll far enough to hit the deep pages. If you want to confirm it on your own data, reading EXPLAIN ANALYZE will show the cost growing with the offset.
There is a second problem that no index can fix. Offset pagination assumes the rows stay still between requests. They do not. A new row inserted before the current page pushes everything down by one, so the next page repeats a row. A deleted row pulls everything up, so the next page skips a row. For a list a user scrolls once, that is a cosmetic annoyance. For a sync job or an export that pages through the whole table, it means missing or duplicated records.
How cursor pagination works instead
Cursor pagination never counts rows. It remembers where the last page stopped and asks for the next rows after that point. The query becomes a simple range scan on an indexed column:
SELECT * FROM claims WHERE id > 10432 ORDER BY id LIMIT 15;
That query costs the same on page 1 and page 10,000, because the database walks the index straight to the starting point. The cursor itself is an encoded value the client passes back, usually as a ?cursor= query parameter. The client never needs to understand it, only to hand it back for the next page.
Using cursorPaginate in Laravel
Laravel ships this as cursorPaginate(). The one rule that matters: the query must be ordered, and the ordering column should be unique. Ordering by id is the safe default. If you order by created_at, add id as a tie-breaker, because two rows can share a timestamp and a non-unique ordering column can still skip or repeat rows.
Route::get('/api/claims', function (Request $request) {
return Claim::query()
->where('organization_id', $request->user()->organization_id)
->orderBy('created_at')
->orderBy('id')
->cursorPaginate(15);
});
The JSON response keeps the familiar shape, with data plus a meta block holding next_cursor, prev_cursor, per_page, and path. The client requests the next page with GET /api/claims?cursor=eyJpZCI6MTA0MzJ9. There is no total and no last_page, and that is by design. Counting every row to show a total would bring back the expensive scan cursor pagination exists to avoid.
What you lose, and how to handle it
Cursor pagination cannot jump to page 47. If your UI has numbered page links, offset pagination is still the right tool for that screen, and you should keep it there. Cursor pagination fits infinite scroll, "load more" buttons, and any background job that walks a whole table. Pick the tool per screen instead of forcing one pattern everywhere.
Sorting is the other trade-off. The cursor is tied to the ordering you chose, so a client cannot reorder results mid-scroll and keep the same cursor. If your endpoint offers sorting, treat a sort change as a fresh list: drop the cursor and start from the first page. A cursor from one sort order means nothing under another.
Testing it before you ship it
Two checks catch most mistakes. First, page through the whole table in a test and assert the collected ids are unique and complete. That catches a missing tie-breaker column immediately. Second, insert and delete rows while paging and confirm the walk still returns each row exactly once. That is the test offset pagination fails and cursor pagination exists to pass.
One more detail worth checking: make sure the column you order by has an index. On id you already have the primary key. On created_at you probably do not, and the range scan will fall back to a sort without one. Add the index, then confirm with EXPLAIN that the query uses it.
Takeaway
Offset pagination is fine for small, stable lists with numbered pages. For anything large, growing, or consumed by a background job, cursor pagination is a small change with a real payoff: constant-time pages, no duplicate or skipped rows, and a query shape your database can serve from an index. In Laravel it is one method call, cursorPaginate(), plus the discipline of a unique ordering. Swap it in on your biggest list endpoint first, and measure the deep pages before and after. The difference is usually obvious.