Skip to the content.

🔹 What is a Cursor in Pagination?

A cursor in pagination is a pointer/marker that tells the database or API where to resume fetching the next set of results.

Instead of using page numbers (page=2, page=3), a cursor-based system uses an encoded ID or token from the last item fetched to get the next set of results.


🔹 Example

Imagine you have a list of users sorted by created_at:

id name created_at
1 Alice 2024-09-01 10:00:00
2 Bob 2024-09-01 10:05:00
3 Carl 2024-09-01 10:10:00
4 Dave 2024-09-01 10:15:00
5 Emma 2024-09-01 10:20:00

Offset Pagination (traditional)

Cursor Pagination

👉 The cursor points to the last seen item, so you always continue from that exact spot, even if new data is inserted.


🔹 Benefits of Cursor Pagination

✅ More consistent for real-time data (avoids duplicates or missing items if data changes). ✅ Faster for large datasets (no expensive OFFSET n scans). ✅ Works well for infinite scroll (social media feeds, chat apps).


🔹 Where It’s Used


👉 In short: Cursor = bookmark to continue fetching results from where you left off.


🔹 Traditional Pagination (pageNumber + pageSize)

This is why offset/page-based pagination is not reliable for real-time data.


🔹 Cursor Pagination (used in WhatsApp/Chats)

👉 Even if new messages arrive while you’re scrolling, they don’t disturb your “older messages” loading, because you’re going back in time using a cursor, not using a page number.


🔹 Why This Works for Chats/Feeds


✅ So yes —