System Design Patterns: From Fundamentals to Real Systems
0% completed
Cursor-Based Pagination
The Pattern
Don't tell the API which page you want: tell it where you left off. A cursor is an opaque bookmark ("everything after order 8412") instead of a page number ("items 101-120"): anchored to a row, not to a count: which makes it immune to the two diseases that kill offset pagination at scale.
Meet the diseases first, because both are live in the store's API today:
Disease one: drift. The mobile app's order feed uses classic pages: ?page=2 means OFFSET 20 LIMIT 20. A user scrolls page 1, and while they read it, three new orders arrive at the top of the list
.....
.....
.....
Like the course? Get enrolled and start learning!