How to Implement Cursor Pagination Like a Pro

Megan C.
The Startup
Published in
10 min readSep 13, 2019

--

So you’ve decided to implement cursor pagination on your website. Well, you’ve come to the right place! (If you’re not entirely convinced cursors is right for you, first, check out the benefits in this article to see if it is, indeed, the right option for you.)

First, you will need a unique, sequential column (e.g. timestamps, usernames, emails, etc.). Keep in mind that the data will be sorted by this column. So if, for instance, you wanted to sort a user list by last name, which is generally not considered a unique column, there will be additional work necessary. (If this is the case, never fear! Scroll to the bottom of this article for some tips to get around this limitation.)

But first, let’s discuss the ideal scenario.

Cursor Implementation

If offset pagination is an array, then cursor pagination is a linked list. Where offset grabs records based on where they are located in the table like an index, cursors use a pointer that points to a specific record and grabs the records following this specific record.

--

--

The Startup
The Startup

Published in The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +772K followers.

Megan C.
Megan C.

Written by Megan C.

Just a software girl livin’ in a startup world | Took the midnight train goin’ to Google | UCSB Master’s in Mechanical Engineering