Overview
The TrackGeek API supports two pagination strategies to efficiently handle large datasets:- Cursor-based pagination - Recommended for real-time feeds and large datasets
- Offset-based pagination - Traditional page-based navigation
Cursor Pagination
Cursor-based pagination uses an opaque cursor string to fetch the next set of results. This approach is more efficient for large datasets and handles real-time updates better than offset pagination.Request Parameters
| Parameter | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
cursor | string | No | - | - | Opaque cursor string from previous response |
itemsPerPage | number | No | - | Min: 1, Max: 50 | Number of items to return |
The first request should not include a cursor. Use the
nextCursor from the response to fetch subsequent pages.Response Format
- nextCursor: Cursor for the next page, or
nullif no more results - hasNextPage: Boolean indicating if more results are available
- items: Array of result items
Example Usage
Example Response
Offset Pagination
Offset-based pagination uses page numbers to navigate through results. This is familiar and intuitive but can be less efficient for very large datasets.Request Parameters
| Parameter | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
page | number | No | - | Min: 0 | Zero-based page number |
itemsPerPage | number | No | - | Min: 1, Max: 50 | Number of items per page |
Response Format
- count: Total number of items across all pages
- pages: Total number of pages
- inPage: Current page number (zero-based)
- itemsInPage: Number of items in the current page
- itemsPerPage: Requested items per page
- items: Array of result items
Example Usage
Example Response
Page numbers are zero-based. The first page is
page=0, not page=1.Choosing the Right Pagination Method
Use Cursor Pagination When:
- Working with real-time data that updates frequently
- Fetching large datasets (thousands of records)
- Building infinite scroll interfaces
- You need consistent results even as data changes
Use Offset Pagination When:
- Building traditional page-based UI (page 1, 2, 3…)
- You need to know the total count upfront
- Users need to jump to specific pages
- Working with relatively small, stable datasets
Validation
Both pagination methods include validation to ensure optimal performance:Performance Tips
- Set appropriate page sizes: Balance between fewer requests (larger pages) and faster response times (smaller pages)
- Cache results: Store paginated results on the client to avoid redundant requests
- Use cursor pagination for feeds: Activity feeds and timelines benefit from cursor-based pagination
- Respect rate limits: Be mindful of rate limits when fetching multiple pages
Implementation Reference
The pagination DTOs are defined at:- Cursor pagination:
src/shared/infra/database/dtos/cursor-pagination.dto.ts:1-31 - Offset pagination:
src/shared/infra/database/dtos/offset-pagination.dto.ts:1-36