Menu

Stop Using Offset Pagination: Scale Laravel with Cursors
🖼️

Stop Using Offset Pagination: Scale Laravel with Cursors

DEV Community·Prajapati Paresh·7 months ago
#Q5CAVADY
Reading 0:00
15s threshold

The Silent Performance Killer: OFFSET

When building data-heavy B2B SaaS platforms at Smart Tech Devs—such as audit logs, infinite-scrolling activity feeds, or massive invoice tables—pagination is mandatory. The default approach in Laravel is using the paginate() method. Under the hood, this uses standard SQL LIMIT and OFFSET .

For the first few pages, OFFSET works perfectly. But what happens when a user navigates to page 1,000 of your audit logs? The database query looks like this: SELECT * FROM audit_logs ORDER BY created_at DESC LIMIT 15 OFFSET 15000 . To execute this, PostgreSQL must sequentially scan, retrieve, and discard the first 15,000 rows just to give you the 15 rows you actually requested.…

Continue reading — create a free account

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