# Our search API answers in 31 ms. Here is how, and what it costs us.

> Source: <https://nestdaddy.com/blog/how-our-search-api-answers-in-31-ms>
> Published: 2026-11-24 23:45:39.887460+00:00

**Recommendation:** Pin your search index in RAM and protect it with systemd MemoryMin, and remove hourly cache-dropping cron jobs and full table scans, since each eviction forces disk reads that spike latency.
More in the playbook "Inference and self-hosting": <https://wpnews.pro/playbooks/inference-serving>

# Our search API answers in 31 ms. Here is how, and what it costs us.

Many web search APIs take one to five seconds. Ours has a 31 ms median. What makes the difference (our own index, kept in RAM), the bugs that made it slow along the way, and the honest price we pay for the speed.

In an independent benchmark of 99 web search APIs, many took one to five seconds to answer. Ours answered in under a tenth of a second.

Our own logs say the same. Over the last 14 days the search endpoint served 10,611 requests:

|  | Server time | 
|---|---|
| Median | 31 ms | 
| 90th percentile | 131 ms | 
| 99th percentile | 762 ms | 

That last line matters, and we will come back to it. First, why the gap is so big.

```
Press Run to call the API.
```

[Get your free API key](https://nestdaddy.com/mcp)

## Why most search APIs take seconds

A typical search API does not own a search index. When you call it, it calls something else: another search engine, a results page it scrapes, sometimes a headless browser that renders pages before it can read them. Every one of those steps is a network round trip to a system the API does not control. You pay for all of them, in order, on every request.

Seconds are what that design costs. No amount of tuning removes a round trip you depend on.

## What we do instead

We crawl the web ourselves and keep our own index. A search never leaves our server. That one decision is most of the 31 ms. The rest is detail, and most of the detail is about not undoing it.

**The index is a key-value store, not a search cluster.** Our index lives in RocksDB, with BM25 ranking on top. We build it in bulk, offline: sorted files loaded straight in, with no compaction work left for query time. When the index was rebuilt in November it held about 35 million pages.

**The index stays in RAM.** This is the big one. A lookup in memory is many times faster than the same lookup on even a fast SSD, and one search does many lookups, so the difference multiplies. We keep the live index pinned in memory with a small service that holds it resident, and we tell the operating system to protect that memory (in systemd terms, `MemoryMin`) so nothing else on the machine can push it out.

**A deadline on every request.** A search request gets a fixed time budget. Optional parts, like finding a thumbnail image, get their own small cap (300 ms). If a part runs out of time, the answer goes out without it instead of waiting.

**Keep-alive connections.** Opening a new connection for every call adds a round trip before any work starts. Clients that keep the connection open skip it.

## The bugs that made it slow

None of this was fast on the first try. Three real problems we hit:

1. **A cron job that emptied our memory every hour.** Search was fast for most of the hour, then slow for a few minutes, every hour. The cause was an old hourly script that told Linux to drop its file cache, which threw our in-memory index out with it. Every hour, the first queries had to read everything from disk again. We removed the script and added the memory protection above, then watched the index stay resident past the hour mark.
2. **A regular expression that took quadratic time.** A pattern meant to spot email addresses in page text slowed down badly on long inputs. Most queries never noticed; a few took far longer than they should. Rewriting it removed a whole class of slow requests.
3. **Full table scans next to the index.** A count over a large database table reads that whole table through the same memory the index lives in, and pushes the index out. Now we avoid full scans on the live server and use indexed ranges or logs instead.

The lesson from all three: when your speed comes from data being in RAM, anything that touches a lot of data on the same machine is a latency bug, even if it looks unrelated.

## What the speed costs us

Here is the honest part.

**Accuracy.** In the same benchmark, our accuracy score was 52 out of 100. The leader scored 93. Speed is easy to measure, and we are proud of ours, but the right answer matters more than a fast wrong one. Most of our misses come from coverage (pages we have not crawled yet) and from long, specific queries where a page matches one generic word and ranks too high.

**Freshness.** We answer from a stored copy, not a live fetch. For most questions that is fine. For something that changed five minutes ago, a live fetch can be newer than our index.

**Memory.** Keeping the index in RAM caps how big it can get on one machine. Adding full page text to the index, which would help accuracy, makes it larger than the memory we keep for it today. Growing means more RAM or splitting the index across machines, both of which cost money.

**The tail.** Our median is 31 ms, but 1 in 100 requests takes more than 750 ms. We have not finished breaking down why; the same machine also crawls and indexes, and that is our first suspect. A fast median does not help the user who hits the slow tail, so this is on our list.

## Is it worth it?

For an AI agent, yes. An agent may search five or ten times to answer one question. At two seconds a search, that is a long wait before the model starts writing. At 31 ms, search stops being the slow part.

But we are not done. The next work is accuracy: indexing page text, not only titles and descriptions, without giving up the RAM that makes it fast. We will publish the numbers when we have them, including if they get worse.

*NestDaddy is an independent search engine and search API with its own crawler and index. You can try the API with [1,000 free credits](https://nestdaddy.com/apis).*
