02 / 03

How to implement Offset-Based Pagination in GraphQL?

Difficulty: 5/10
offset pagination, GraphQL resolvers, performance

Pagination in GraphQL allows you to efficiently manage large datasets by retrieving small chunks of data rather than fetching everything at once. There are two common approaches to implement pagination in GraphQL: Offset-Based Pagination and Cursor-Based Pagination.

Schema Definition:
Resolver:
Query Example:

Scenario Questions

0-2 years experience

  1. 1We have a simple GraphQL query `posts(page: Int, pageSize: Int): [Post]`. How would you implement offset‑based pagination in the resolver?
  2. 2If a client asks for `page: -1` or `pageSize: 0`, what should your resolver return and why?

2-5 years experience

  1. 1Your team added offset pagination to a product list, but after deployment some users see duplicate items when navigating quickly. What could cause this and how would you fix it?
  2. 2Explain the trade‑offs between using `OFFSET/LIMIT` in SQL versus using keyset pagination for a feed that can have millions of rows.
  3. 3During a load test, queries with high offset values become slow. What indexing or query‑optimisation strategies would you apply?

5-8 years experience

  1. 1Design a GraphQL pagination layer that supports both offset and cursor pagination, allowing clients to choose. How would you structure the schema and resolver logic to keep them consistent?
  2. 2Your service must serve paginated results from multiple data sources (SQL, Elasticsearch). How would you abstract offset pagination to handle differing pagination mechanisms while keeping response shape uniform?
  3. 3Consider a dataset that is frequently updated (new rows inserted). How would you ensure that offset pagination does not miss or duplicate items across pages?

8+ years experience

  1. 1A legacy monolith uses offset pagination in its GraphQL API, but the new microservice architecture prefers cursor pagination for scalability. How would you plan and execute a migration strategy that minimizes breaking changes for existing clients?
  2. 2Across several teams, offset pagination is causing performance bottlenecks at high offsets. As a staff engineer, how would you drive a cross‑team initiative to replace or augment offset pagination, including metrics, rollout, and backward compatibility?
  3. 3If you need to support internationalization where sorting order changes per locale, how does that impact offset pagination implementation and what architectural changes would you recommend?

Follow-up Questions

  • What happens if the client requests a very large offset?
  • How would you expose the total number of items without a costly count query?
  • Can you explain how sorting order affects offset pagination consistency?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.