Member-only story
Building APIs: A Comparison Between Cursor and Offset Pagination
Which makes the most sense for your API?

Overview of Pagination
When you have an extensive database that needs to be sent to the user and you decide to send it in chunks rather than sending the entire database in one go, pagination comes into play. The concept of pagination is used by almost all the sites that are visited daily.
Before diving deep into pagination, you must know about the two different types of pagination.
Cursor-based pagination
The cursor is considered to be a key parameter in this type of pagination. The client receives a variable named Cursor
along with the response. It is a pointer that points at a particular item that needs to be sent with a request. The server then uses the cursor to seek the other set of items. Cursor-based pagination is more complex and is preferred when dealing with a real-time data set.
Offset-based pagination
Offset-based pagination is a very famous technique wherein the client requests parameters with a specific limit (the number of results) and offset (the number of records that need to be skipped). Offset-based pagination is easy to use and is preferred for static data.
Pros and Cons
Cursor-based pagination is considered one of the most effective pagination methods and must be integrated wherever possible.
The advantages of cursor-based pagination compared to offset pagination are:
- No data is skipped. Rather than sending an offset parameter that behaves like an index, cursor pagination sends a cursor parameter that behaves like a pointer to a particular record present in the database to show where the last page was left off.
- Excellent real-time data capabilities. One of the most significant advantages of cursor pagination is its ability to manage real-time data very efficiently. The main reason behind this is that cursors do not need static data. Thus, new rows or items can be easily removed or added without affecting each page’s loading procedure. Due to the increase in real-time applications with time…