A guide to offset pagination

To help you fetch data from a 3rd-party resource quickly and without overwhelming your server, you’ll need to leverage API pagination.

And while there are many pagination methods to consider, offset pagination, or offset-based pagination, is likely at the top of your list.

We’ll break down how this method works so that you can decide whether it’s the right fit for any of your integration scenarios.

What is offset pagination?

It’s an approach to pagination that uses an offset to determine the starting point of data to fetch from a request and a limit to set the volume of data that should be returned from each request.

Example of offset pagination

To prevent any confusion, we’ll distinguish offset pagination from other methods.

Offset pagination vs cursor pagination

Cursor pagination lets you define the starting point of each request via a unique identifier (e.g., a timestamp), while offset pagination simply skips a predefined set of items with each request.

Offset pagination vs keyset pagination

Similar to the above, keyset pagination uses a key to determine the starting point of a request while offset pagination just skips a predetermined set of data.

Offset pagination examples

To help bring our definition to life, let’s walk through a few examples of offset pagination.

Employees

Say you want to get a list of employees from an HRIS solution and each page includes 30 employees. 

Your first request can be structured as follows:
<code class="blog_inline-code">GET /v1/employees/?offset=0&limit=30</code>

Product reviews

Say you want to fetch reviews from a specific product (e.g., product ID=12345) and from a certain site. Let’s also assume that the site shows 10 reviews per page and you only want to get reviews that are on the 3rd page.

To retrieve these reviews, you can make the following request:
<code class="blog_inline-code">GET /v1/products/12345/reviews?offset=20&limit=10</code>

Related: Everything you need to know about REST API pagination

Invoices

Imagine that you want to retrieve invoices from your ERP system. You also only want to retrieve invoices from a certain vendor (e.g., vendor ID=12345) and you decide to only retrieve 5 invoices at a time.

You can structure your first request to something as follows:
<code class="blog_inline-code">GET /v1/invoices/12345/?offset=0&limit=5</code>

Offset pagination pros and cons

Now that you know how offset pagination works and how it differs from other methods, you may be wondering what its benefits and drawbacks are. 

We’ve broken them down below.

Pros

  • It’s relatively easy to implement and understand, as the offset is usually determined by the page size
  • It’s easy to access a specific set of data via the offset
  • It’s widely support by API providers, so understanding how it works and how to leverage it can prove useful for many, if not all, of your integrations

Cons

  • If a dataset grows or shrinks, you can end up skipping or double counting data
  • Even with a large offset, every data point needs to be processed. As a result, requests with a large offset can take a while to execute and consume significant computational resources
  • If a dataset isn’t paginated or sequentially ordered in another intuitive way, offset pagination can end up yielding confusing and inconsistent responses

Related: Tips for implementing API pagination effectively

Manage pagination with ease by using Merge

Merge, the leading unified API solution, lets you connect your product with hundreds of 3rd-party SaaS applications through the platform’s unified API.

This means you only have to consider how Merge’s Unified API handles pagination (among other items, like rate limits and authentication), which helps you scale your integration builds more quickly and maintain them more easily.

You can learn more about Merge’s Unified API, among the platform’s other features, by scheduling a demo with one of our integration experts.