DEV Community

Pratham Israni
Pratham Israni

Posted on

My keyword search took 5 seconds over 355k jobs, and C++ matched random jobs

Architecture diagram of the job index. A nightly GitHub Action commits per-company job JSON files. A sync script loads them into Supabase Postgres (jobs, companies, job_countries). The free Next.js UI on Vercel queries Supabase directly. On the paid path, an Apify Actor is run by the buyer, calls a Cloudflare Worker, which reads Supabase through Hyperdrive with a read-only role. A Durable Object rate limiter, keyed by API key, sits beside the Worker. The Actor writes each result to its dataset.

I'm building a searchable index of about 310,000 open jobs from roughly 6,800 company career pages, mostly Indian IT and services firms. Most of them publish their openings through public job feeds, so I pull from those.

The 5-second search

My first keyword search used ILIKE over title and company. On 355k rows, EXPLAIN ANALYZE showed a full sequential scan at about 5 seconds, which is too slow for a search box.

Trigram indexes fixed the speed but used too much storage on the free tier. I switched to a GIN index over to_tsvector('simple', ...). I chose simple over english because english stems words and drops stopwords, which makes results hard to predict.

The C++ problem

With the new index, searching for C++ returned unrelated jobs. Postgres reduces C++ to a bare c token under both text configs, and .NET to net. So a C++ search matched anything with a standalone "c" in it.

The fix is a normalization step applied on both sides of the search:

  • c++ → cpp
  • c# → csharp
  • .net → dotnet

It runs in the index expression and in the query builder, so they stay in sync. The catch is that these rules live in two places, and I have to keep them matching by hand.

Rate limiting, what didn't work

My first limiter was a globalThis Map on Vercel. Every cold start reset it, so it wasn't really a limit. Cloudflare's native rate-limit binding didn't enforce for me either. I sent 220+ requests and got zero 429s.

A Durable Object keyed by API key (idFromName(apiKey)) worked. It started returning 429 around request 62, and other keys weren't affected.

Hyperdrive setup gotchas

  • Use Supabase's direct connection (port 5432). Hyperdrive does its own pooling.
  • Use one pg Client per request.
  • On Supabase, GRANT postgres TO hyperdrive_user isn't allowed. I granted scoped SELECT and added an RLS policy for that role only.

What it doesn't do

  • No job descriptions. Title, company, location, apply link, and dates only.
  • Refreshes about once a day. Each row has lastSeenAt.
  • About a third of rows have no city.
  • No salary. The sources don't publish it consistently.

If you've run a similar setup, I'd like to know how you handled keyword search over a large table without a trigram index.

The Actor is here if you want to look at the data: https://apify.com/pk07007/ats-jobs-api

Top comments (0)