Text size
Dark mode
RecallRunGuides & benchmarks
Learn to build real systemsGuides•Benchmarks•Experiments•Community
Search the site/Free checklist

Community/Tech articles

Catch skipped API records with a five-row pagination fixture

Run a small Python test that exposes a timestamp-only cursor bug, checks a compound cursor, and shows why stable page boundaries are not snapshot consistency.

In this post

A list endpoint can pass a normal smoke test and still skip records at a page boundary. Five rows are enough to expose one common mistake: using only a non-unique timestamp as the next-page cursor.

This is a small, synthetic Python experiment, not a report about a production system or customer. The full script below ran with Python 3.10.12 and uses only the standard library. It does not make network requests, connect to a database, or modify files.

Choose data that makes the boundary ambiguous

The fixture deliberately assigns three records the same creation tick. The page size is two, so that group cannot fit on one page. Each row has an immutable, unique identifier as well. A tick is an integer here to remove timezone and timestamp-format distractions.

The expected ascending order is (10, a), (10, b), (10, c), (11, d), (12, e). If page one returns a and b, a timestamp-only condition of created_tick > 10 drops c. Changing it to >= 10 alone would repeat earlier rows instead of solving the boundary.

The alternative tested here keeps the entire last-seen (created_tick, unique_id) tuple and asks for keys strictly after it in the same ordering. Python compares tuples lexicographically: timestamp first, then identifier. The fixture uses simple ASCII identifiers. A database implementation must explicitly choose matching sort and comparison rules; do not assume its collation matches Python's strings.

Run the complete experiment

Save this as check.py and run python3 check.py. Every expected result is asserted, including the deliberately incorrect timestamp-only page. An assertion failure means the experiment did not match the stated result.

from bisect import bisect_right

# Ascending immutable (created_tick, unique_id) keys, entirely synthetic.
rows = [(10, 'a'), (10, 'b'), (10, 'c'), (11, 'd'), (12, 'e')]
size = 2


def page(data, after=None):
    keys = sorted(data)
    start = 0 if after is None else bisect_right(keys, after)
    return keys[start:start + size]


first = page(rows)
assert first == [(10, 'a'), (10, 'b')]
wrong_second = [r for r in rows if r[0] > first[-1][0]][:size]
assert wrong_second == [(11, 'd'), (12, 'e')]
assert (10, 'c') not in first + wrong_second

seen, cursor = [], None
while True:
    batch = page(rows, cursor)
    if not batch:
        break
    seen += batch
    cursor = batch[-1]
assert seen == rows
assert len(set(seen)) == len(rows)
assert page(rows, first[-1]) == page(rows, first[-1])
assert page([]) == []
assert page(rows, rows[-1]) == []

# Insert behind and ahead of the cursor after returning the first page.
changed = rows + [(9, 'old'), (10, 'bb')]
assert page(changed, first[-1]) == [(10, 'bb'), (10, 'c')]
assert (9, 'old') not in page(changed, first[-1])

# An insert before the offset shifts previously returned data into page two.
assert sorted(rows + [(9, 'old')])[size:size + size] == [(10, 'b'), (10, 'c')]
print('timestamp-only: missed c')
print('compound cursor: 5 rows once; replay stable; end and empty checks passed')
print('mutation: bb visible after cursor; old excluded; offset repeats b')

Expected output from the executed run:

timestamp-only: missed c
compound cursor: 5 rows once; replay stable; end and empty checks passed
mutation: bb visible after cursor; old excluded; offset repeats b

What the output proves

The timestamp-only control misses c. The compound cursor visits all five original rows exactly once. Replaying the same cursor against the unchanged input returns the same page. Empty input and a cursor at the final record produce empty pages.

These are small, deterministic assertions about this function, not a database benchmark or proof of an API's correctness. The function sorts the whole input for clarity. It is not an efficient server implementation, and the script does not measure query plans, indexes or latency.

Mutation is a separate contract

After returning the first page, the experiment inserts two synthetic records. (10, bb) sorts after (10, b) and appears in the next compound-cursor page. (9, old) sorts behind that cursor and will not appear when continuing forward. A stable boundary does not imply a frozen dataset.

The offset control demonstrates a different problem: inserting one record before an offset of two shifts previously returned b into the next page. That is why a static five-row pass alone is too weak an acceptance test for a changing feed.

Neither result makes cursor pagination a snapshot. If a client needs a complete point-in-time export, the application needs a separate consistency design. A maximum timestamp alone does not prevent later backdated inserts inside that range. If timestamps or identifiers can change after a row is returned, even the assumptions of this example no longer hold.

Turn the experiment into API acceptance checks

Before testing an actual endpoint, write down its ordering and consistency contract. Then put several equal sort values across a real page boundary. Check the combined identifiers from every page, rather than looking only at individual responses.

Repeat a cursor against unchanged data. Test an empty result, an exact final-page boundary and a dataset smaller than one page. Insert before and after the cursor, delete an unseen record, and update a sort field if the product permits that operation. Compare outcomes with the documented contract, not with an assumption that every traversal is a snapshot.

An actual endpoint also needs tests this local function intentionally omits: invalid or altered cursors, page-size bounds, authorization filters, tenant separation, encoding, and database comparison semantics. A cursor must never let a client cross an access boundary. This article is not a secure cursor implementation.

The useful lesson is to make the failure case small enough to understand. Three equal timestamps, a two-row page, and assertions on the complete traversal reveal more than a large fixture whose records all have different timestamps.

Disclosure

Prepared for Omnistu with AI assistance, using original synthetic data and executed checks. No client work, deployment experience or performance claims are implied. AYUSH ANAND is Omnistu's founder; the company website is https://omnistu.com/ . This example is educational and is not a product endorsement.

Written by

AYUSH ANAND

Founder of Omnistu. Sharing clearly labelled, AI-assisted software test examples with synthetic data and reproducible checks, not claims about client deployments.

Website

Written by AYUSH ANAND for the RecallRun community. Community posts are checked for safety and reviewed by our editors before publishing, but the views and claims are the author's own. Links are the author's; open them with care. Report this post.

More from the community

Write for RecallRun

Share a tech article or a tool you built. Every post is checked and reviewed before it goes live.

Start writing