Evolving API Pagination at Slack

At Slack, the size and scope of the data we expose via our APIs has changed dramatically since the product first launched. Endpoints that were designed around the expectation that they would, in the most extreme cases, return several hundred records, are now returning hundreds of thousands of records. To handle this rapid growth, we’ve…

Michael Hahn
13 min readintermediate
--
View Original

Overview

The article discusses the evolution of API pagination at Slack, highlighting the challenges faced as data volumes increased and the strategies implemented to improve data retrieval efficiency. It covers various pagination methods, including offset and cursor-based pagination, and details the requirements that guided Slack's new pagination scheme.

What You'll Learn

1

How to implement cursor-based pagination for APIs

2

Why cursor-based pagination is preferred over offset pagination for large datasets

3

When to use Relay Cursor Connections in GraphQL APIs

Key Questions Answered

What are the pros and cons of offset pagination?
Offset pagination allows users to see the total number of pages and jump to specific pages, making it easy to implement. However, it does not scale well for large datasets and can lead to unreliable results if items are added during pagination.
How does cursor-based pagination improve performance?
Cursor-based pagination improves performance by using a pointer to a specific item, allowing the server to fetch results without reading previously seen rows. This method scales better for large datasets and stabilizes the pagination window, reducing issues with data consistency.
What is the structure of Relay Cursor Connections?
Relay Cursor Connections define a structure for paginating data in GraphQL, consisting of connections, edges, nodes, and pageInfo. This allows clients to paginate forwards and backwards from any item, providing a flexible and robust pagination scheme.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

API
Graphql
Used for implementing Relay Cursor Connections to enhance pagination.
Database
SQL
Used for querying data with offset and cursor-based pagination strategies.

Key Actionable Insights

1
Implement cursor-based pagination to enhance API performance and reliability.
As datasets grow, cursor-based pagination helps maintain efficient data retrieval and prevents issues with data consistency, making it a better choice for modern applications.
2
Consider using Relay Cursor Connections for GraphQL APIs to improve user experience.
This approach allows for flexible pagination, enabling clients to navigate through data efficiently, which is particularly useful in applications with dynamic data sets.

Common Pitfalls

1
Relying solely on offset pagination for large datasets can lead to performance degradation.
As the offset increases, the database has to read more rows from disk, which can slow down response times. Transitioning to cursor-based pagination can mitigate these issues.

Related Concepts

API Pagination
Data Retrieval Strategies
Graphql Apis