All posts
Engineering

Paging a jobs API fast: cursors, limits and counts

What a jobs query costs is the shape of the request: deep offsets, totals, descriptions in bulk, re-walks. Page fast with cursors, limit and /v1/jobs/count.

HyperJobs Team6 min read

The catalogue is indexed for the filters people actually use, and a normal filtered query on /v1/jobs is fast. What still costs is the work no index can skip, and that work is decided by the shape of your request: how deep you page, whether you ask for a total, whether you pull descriptions, and whether you walk the whole set to stay current.

This post is about those four, and the habits that keep a client fast.

"Faster" and "smaller" are two different wins

A request does three kinds of work, and only one of them is about finding rows:

CostDriven byDoes narrowing help?
Finding the rowsYour filtersYes: a tight filter reaches fewer rows
Serialise + transferlimit, and whether descriptions are onYes
Parse on your sideThe sameYes

So the mental model is: finding the rows is cheap when the filter is specific, and everything after that is priced by the row. Normal filtered queries are fast; the costs worth designing around are the ones below.

One filter is worth singling out. description= is a Google-style search over the description (words AND, "quoted phrases", OR, -exclusions, and description_advanced= for boolean grouping), and it is the most expensive filter you can send: pair it with something narrower. q= is the one that spans title and description. And if you are reaching for description=react when skill=react exists, you are asking a text search a question a classifier already answered.

A page doesn't count

A list never counts its matches, so a page costs the same whether 5 jobs match or 5 million. has_more says whether another page follows, and that is all a loop needs.

When you want the number itself, /v1/jobs/count takes the same filters and bills no jobs. It is exact up to 10,000 matches; past that it is an estimate, flagged estimated: true. That is the right trade for a dashboard tile, and worth knowing before you print the figure as if it were exact. If the question is only "are there any", fetch limit=1 and check data.length instead.

Offset is discarded after the work is done

  1. GET /v1/jobs

    offset=10000

  2. Find

    the matching rows

  3. Order

    newest first

  4. Discard offset

    10,000 rows thrown away

  5. Return limit

    50 rows

offset=10000 doesn't skip work: the rows are found, filtered and ordered, and then thrown away at the end.

This is true of offset paging in any database, not just ours. offset is not a seek: page 200 costs everything page 1 costs, plus reading and ordering the 10,000 rows it throws in the bin. That is why offset caps at 10,000 and why the deep-paging answer is the cursor: pass back next_cursor and the keyset condition (older than the last row you saw) replaces the discard. The walk stops getting more expensive as it goes, and (the part that matters more in practice) it stops drifting.

While you are here: don't turn descriptions on in bulk. description_format on a limit=200 list is the most common reason a request feels slow, and that one is not finding the rows at all: it is multi-kilobyte payloads, 200 at a time. List without them, then pull the postings you care about from /v1/jobs/{id}.

The index moves while you walk it, unless you cursor

Results are newest-first and new jobs arrive all the time. Offset paging over that is not a consistent snapshot: 30 new jobs landing while you're on page 3 shift every row down, so you see 30 rows twice and miss rows falling off the far end.

The cursor removes the problem: next_cursor pins your position to a row rather than a row number, so inserts above you shift nothing. Page until it comes back null: that is the loop, whole. (Pagination has the mechanics.)

JS
let cursor = null;
do {
  const qs = new URLSearchParams({ skill: "rust", limit: "200" });
  if (cursor) qs.set("cursor", cursor);
  const res = await fetch(`https://api.hyperjobs.io/v1/jobs?${qs}`, {
    headers: { Authorization: `Bearer ${process.env.HYPERJOBS_KEY}` },
  });
  const { data, next_cursor } = await res.json();
  for (const job of data) store.upsert(job);
  cursor = next_cursor;
} while (cursor);

Offset still exists for what it's good at: shallow, human-shaped paging where page 2 means "show me a few more".

The arithmetic that should settle it

Walking a whole result set is safe with cursors. It is still the wrong shape of work for staying current.

The quota counts rows returned, so one full walk of a set costs the set. That's fine: it is a bootstrap, you do it once, on a plan sized for it. Repeat it hourly and you pay for the whole set about 720 times a month, re-downloading data that changed by a small fraction between walks.

Polling /v1/jobs/feed, /v1/jobs/expired and /v1/jobs/modified every 15 minutes (births, deaths, and edits) is 8,640 requests a month against the per-minute rate, and in jobs it costs exactly the churn: a poll that finds nothing bills nothing. Its cost scales with what changed rather than with what exists. Feed sync has the loop, and for everything at once there is the dataset in files.

The cheapest thing you can do

There is no default time_frame, and no ceiling either: the catalogue serves every open posting, whatever its age. Ask for the part you mean.

BASH
# Rust jobs posted in the last week.
curl -G https://api.hyperjobs.io/v1/jobs \
  -H "Authorization: Bearer $HYPERJOBS_KEY" \
  --data-urlencode "skill=rust" \
  --data-urlencode "time_frame=7d" \
  --data-urlencode "limit=50"

It shrinks the rows to find and order, the payload and your parse, and it makes the rows you get back mean something. One parameter.

/v1/jobs is for search: an intent, a tight filter, a few pages. The feeds are for completeness. The performance habits are in dataset coverage; the paging mechanics are in pagination.