Direct answer
No step size guarantees consistent series coverage across paginated topk calls. topk(N, query) is not a cursor or offset mechanism, and Prometheus has no native OFFSET or LIMIT for the HTTP API. Shrinking the time window changes the values used for ranking, so the same N does not preserve membership or ordering across windows. Prometheus 2.x does not expose a topk-specific materialization cap; label matchers and the requested time range are applied before topk, which filters only after the inner expression has been evaluated for every selected series. General query limits vary by version and startup flags.
Confirmed behavior versus likely explanation
Confirmed: step changes sample density for range-vector inputs such as max_over_time, which can change ranked values and therefore which series enter the top N. Ties are not deterministically ordered unless you add an explicit tie-break. Repeated topk calls over changing data can return different series, producing duplication or gaps.
Likely explanation: if you paginate by shrinking [start, end], each call ranks a different population. A series inside the top N for the first window can fall out for the next, and vice versa, even when raw samples are stable. That makes value-based bounding unsuitable for stable time-window pagination by itself.
Steps for this case
- Fix the ranking expression, window length, and tie-break labels. Do not vary
step or the time window between pages if stable membership is required. - Paginate by label sets or fixed time buckets instead of repeating
topk over shifting windows. - Add a deterministic tie-break, such as sorting by label or filtering to a static label set, before applying
topk if order matters. - Verify on the target binary: run the same
topk query with two different step values against a range-vector aggregation and compare the returned series sets; then run two adjacent windows with identical N and compare membership.
Safe verification commands
curl -G 'http://localhost:9090/api/v1/query' --data-urlencode 'query=topk(10, max_over_time(http_requests_total[5m]))' --data-urlencode 'time=2026-12-03T20:00:00Z'
Repeat the range query with step=15s and step=60s, then diff the series names. Next query two adjacent non-overlapping windows with identical topk N and diff again. These are read-only API calls.
Missing diagnostic detail
Is the expression inside topk an instant vector or a range-vector aggregation such as max_over_time? Step size affects ranking only in the latter case, so this detail changes whether step is even relevant to your pagination gap.
Assumptions and uncertainty
This assumes Prometheus 2.x. Specific resource-guard defaults and flags are version-dependent; consult the release notes for the installed binary rather than assuming a documented materialization limit. PromQL has no explain plan, so confirm behavior by inspecting query results and engine logs.