Resources · 86

API pagination: complete exports without missing or duplicated records

Define ordering, tokens, authorization and recovery when a collection changes during traversal.

· 3 min

Laptop displaying code on a desk Illustration · fictional scene

What this guide helps achieve

  • Define ordering and scope
  • Treat tokens as continuation
  • Detect completion from the contract
  • Recover after failures
  • Reconcile the result

Quick check

  • Does an empty page mean completion?
  • Can a cursor provide authorization?
  • Does deduplication prevent missing records?

Step-by-step method

  1. 01

    Define ordering and scope

    Document filters, ordering and a tie-breaking key. A timestamp alone may be insufficient when several objects share it. Decide whether the collection stays live or the export uses a snapshot. Do not promise a frozen view when the provider offers no such guarantee.

    Deliverable: ordering and consistency contract.

  2. 02

    Treat tokens as continuation

    AIP-158 specifies opaque tokens and separates pagination from authorization: a token does not confer access rights. Check identity and permissions on every request. Keep reading parameters consistent with the contract and handle expiry or invalidation explicitly.

    Deliverable: valid, expired and unauthorized token cases.

  3. 03

    Detect completion from the contract

    Do not assume completion because a page is shorter than requested. An API may return fewer items while providing continuation. Under AIP-158 an empty next_page_token indicates completion; adapt clients to the provider’s actual contract. Also detect repeated tokens without progress.

    Deliverable: completion and loop tests.

  4. 04

    Recover after failures

    Save continuation after durable storage of the processed batch. Deduplicate using stable identifiers and keep recovery state separate from displayed totals. If a snapshot expires, restart or reconcile under an explicit policy; do not silently concatenate two different collection states.

    Deliverable: checkpoint and failure scenario.

  5. 05

    Reconcile the result

    Compare unique identifiers, exclusions, states and any reference total at a common cutoff. Test creation, changes and deletion during reading. A correct count does not prove the right objects were exported. Protect files and traces according to their data.

    Deliverable: export manifest and documented differences.

A paginated read that can recover

Under an AIP-158-style contract, continuation determines the next step. A short page does not establish completion.

  1. Define the read

    Retain filter, order, parameters and authorized identity.

  2. Store the batch

    Durably save objects and their identifiers.

  3. Follow continuation

    A present token leads to the next request with bound parameters.

  4. Reconcile at completion

    When the final token is empty, check exclusions, reference state and coverage.

Fictional example: the connection fails after batch storage. Recovery uses the saved checkpoint and checks identifiers already processed.

Reusable worksheet

Complete with your authorised observations. These fields are a working template, not observed results.

FieldInformation to record
CollectionFilters, order, tie-breaker and guarantees
ContinuationToken, linked parameters, expiry and completion
RecoveryDurable batch, unique identifiers and saved checkpoint
ResultManifest, exclusions, cutoff and reconciliation differences

Worked example

Illustrative situation

Fictional example: products are added while a catalog is exported using offsets, moving a row between pages.

Decision and expected evidence

Testing finds a repeat and an absent product; the team chooses an available API snapshot or documents live reading with reconciliation.

Distinguish the mechanisms

MechanismPurposeCheck or limitation
OffsetAccess a numeric positionInsertions can shift positions
CursorContinue from a reading markerDoes not itself guarantee a snapshot
SnapshotFix a reference stateCheck validity period and cost

Management indicators

IndicatorWhat it measuresFirst action
Unique identifiersDistinct objects retained in the exportCompare with an equivalent reference scope
ProgressTokens and batches genuinely advancingStop loops and investigate
Verified coverageObjects reconciled with a reference stateDo not equate volume with completeness

Common pitfalls

  • Insertions can shift positions
  • Does not itself guarantee a snapshot
  • Check validity period and cost

Frequently asked questions

Does an empty page mean completion?

Check the contract and continuation token. Page size alone should not determine completion.

Can a cursor provide authorization?

No. The server must check request permissions independently of the pagination token.

Does deduplication prevent missing records?

No. It removes repeats without recovering unread objects. Test ordering stability and collection changes.

Official references

References consulted: . The method and worksheet propose checks to adapt to your context; they do not constitute certification.