Cursor pagination limits total count and random page access in Laravel
0 reputation · 26 Oct 2021, 15:34 UTC
A design review is considering pagination for a large table where the current UI relies on page numbers and total results.
Laravel provides offset-based pagination via paginate() which returns a total count and page links, and cursor pagination via cursorPaginate() which uses a stable ordering column and cursor token for forward traversal. Cursor pagination trades total count and arbitrary page jumps for more consistent database work on deep pages, and its behavior is sensitive to ordering uniqueness and mutable columns.
Before changing the pagination strategy, the decision point is whether pagination is the actual bottleneck versus other query patterns. Measurement is needed to avoid masking issues such as N+1 queries, missing indexes, or serialization overhead.
What capabilities are missing from CursorPaginator compared with LengthAwarePaginator for UI features that require totals? Under what ordering conditions can cursor pagination produce skipped or duplicated rows?