Algolia Search API vs. Client Pagination: Is Stable Ordering Guaranteed Across Pages?
0 reputation · 01 Aug 2026, 03:00 UTC
0 reputation · 01 Aug 2026, 03:00 UTC
Developers often need to present users with a paginated view of a sizable Algolia index (tens of thousands of records). The goal is to fetch each page in sequence while ensuring that no record is omitted or duplicated, even when the index is updated between requests.
Algolia’s public API offers hitsPerPage and page parameters, and the more granular offset and length options. However, the API does not guarantee a stable ordering across successive calls when the underlying index changes. The nbHits field is computed on the fly, so its value may not reflect real‑time updates. Additionally, the API lacks a native cursor‑based mechanism, forcing developers to implement custom logic if they wish to track state (e.g., using the last record’s primary key). These factors create uncertainty about whether offset‑based pagination can reliably deliver consistent results for large, frequently updated datasets.
1. Does Algolia guarantee stable ordering across pages when using offset and length or page and hitsPerPage, even when records are added or removed between requests?
2. What, if any, mechanisms does Algolia provide to maintain consistency across paginated results for dynamic indices?
3. For indices that exceed a few thousand records and receive frequent updates, is a custom cursor strategy (e.g., filtering by a monotonically increasing primary key) recommended, and what are the trade‑offs in terms of latency and API usage?
33775 reputation · 01 Aug 2026, 12:08 UTC
Algolia does not guarantee stable ordering across successive calls that use offset/length or page/hitsPerPage when the underlying index is modified between requests. New documents can shift the internal ranking, causing records to appear on a different page or to be omitted entirely.
nbHits field is calculated per query, so it may not reflect the current total after an update.objectID or a custom seq_id) is the only supported way to achieve deterministic paging.seq_id that increments with each new record and is indexed for filtering.hitsPerPage=10 and record the highest seq_id returned.filters=seq_id > 12345 (where 12345 is the last seen seq_id) together with hitsPerPage. This guarantees that only newer records are returned, even if older ones were inserted or removed.seq_id (or objectID if it is monotonically increasing) on the client side. Pass it back to the server with each request.seq_id.offset=0, hitsPerPage=10) and note the returned seq_id values.seq_id that would appear before the current offset range.offset=10, hitsPerPage=10 and observe whether any records from the first page re‑appear or are missing.filters=seq_id > lastSeen) to confirm stability.Do you have a unique, monotonically increasing attribute (e.g., seq_id or a timestamp) that can be indexed for filtering? This is critical for implementing the cursor strategy safely.
For indices that grow or change frequently, rely on a cursor‑based approach with a monotonic filter rather than plain offset or page parameters. This avoids duplicates, omissions, and the pitfalls of an unstable nbHits count.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.