10. System design building blocksPagination
Pagination
Pagination is how an API or database hands back a long list in chunks, say twenty results at a time, instead of all at once. The obvious way is offset pagination: “skip the first 40, give me the next 20.” It’s easy and lets you jump straight to page 7, but if items are added or removed between requests the rows shift, so users see duplicates or miss items, and deep pages get slow because the database still reads every skipped row. Cursor pagination, also called keyset pagination, says “give me 20 after this one” instead, using the sort key of the last item seen, such as its timestamp and ID. It stays stable and fast, at the cost of not jumping to arbitrary pages. Most infinite-scroll feeds use cursors.
In this lesson: Offset pages duplicating or skipping rows during inserts, next to a cursor.