<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Engineering unfiltered]]></title><description><![CDATA[Engineering without the sugarcoating. A collection of real-world engineering problems, architectural decisions, failed experiments, performance bottlenecks and ]]></description><link>https://redis-keys-explained.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 01:31:52 GMT</lastBuildDate><atom:link href="https://redis-keys-explained.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Drishti 1.0: Inside the Crawler Behind Developer's Eye]]></title><description><![CDATA[Building a high-performance web crawler with Python and PostgreSQL. Solving deadlocks, worker contention, rate limiting and concurrency bottlenecks.]]></description><link>https://redis-keys-explained.hashnode.dev/drishti-1-0-inside-the-crawler-behind-developer-s-eye</link><guid isPermaLink="true">https://redis-keys-explained.hashnode.dev/drishti-1-0-inside-the-crawler-behind-developer-s-eye</guid><category><![CDATA[Python]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[System Design]]></category><category><![CDATA[web crawling]]></category><category><![CDATA[Backend Development]]></category><category><![CDATA[concurrency]]></category><category><![CDATA[Open Source]]></category><category><![CDATA[search engine]]></category><dc:creator><![CDATA[Nishchup]]></dc:creator><pubDate>Tue, 24 Nov 2026 05:11:04 GMT</pubDate><content:encoded><![CDATA[<img src="https://nish-chup-one.vercel.app/writing/drishti-1/01-cover-drishti-logo.webp" alt="Drishti Bot fox logo" style="display:block;margin:0 auto" />

<h2>What is a crawler, and why do we need one?</h2>
<p>When you search something in google it processes that query from billions of pages in its database. Ever wondered who stored those billions of pages? Not google employee manually parse them and add them…</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/02-who-stores-the-pages.webp" alt="Someone staring at a screen, wondering who stored billions of pages" style="display:block;margin:0 auto" />

<p>if so then when you make a new website and host it how google find it and already start indexing? Your domain provider informed google? Why they didnt invite duckduckgo or yahoo? If someone make a new website they need to make a new business deal with them? The answer is NO.</p>
<p>Thats why crawler exists. Its job is to fetch a website which is initially added as seed , find links from those website to other website , visit those websites and keeps going. Just link how a spider traverse its web.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/03-crawler-web.png" alt="Pages linked together like a spider web, with a crawler moving between them" style="display:block;margin:0 auto" />

<p>So a crawler basically check source registry find more hyperlinks fetch them safely respect their policy decide weather its worth keeping and hand it to indexer. Indexer helps indexing all documents in database by keywords or lexems like “python” “javascript” which makes the database query a lot cheaper. CHEAPER HOW?</p>
<p>Imagine someone searched “python async” and the database have 100k of documents. Without indexer database will go find that keyword from one docs repeat it 100k times , sort relevant documents and rank them. But indexer already do this task before , database pressure reduced from 100k query to ~ 1 query ( depends on the query).</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/04-indexer.webp" alt="Crawled pages go through the indexer and become a searchable index" style="display:block;margin:0 auto" />

<hr />
<h2>What is Drishti?</h2>
<p>Drishti (দৃষ্টি) means "sight" or "vision" in Bangla and Sanskrit. It is the eye in Developer's Eye. On the wire it identifies itself as <code>DevelopersEyeBot</code>.</p>
<p>Just like other search crawlers like GOOGLE - google bot , Bings - bing bot , Baidu - baiduspider, we have drishti bot.</p>
<p>The logo was inspired from a gaming character name <code>HSIN</code> and mostly symbolize fox while the name itself symbolize vision.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/05-drishti-logo.webp" alt="Drishti Bot logo: a green and white fox" style="display:block;margin:0 auto" />

<img src="https://nish-chup-one.vercel.app/writing/drishti-1/06-hsin.webp" alt="HSIN, the character that inspired the logo" style="display:block;margin:0 auto" />

<p>The whole idea is basically instead of sending a spider we are sending a fox ( a sentinel fox ) [ in v2.0 ] which will not fetch unrelated garbage and will only bring quality documents.</p>
<p>Drishti 1.0 is a focused crawler. It doesn't try to crawl the whole web. It crawls a curated set of developer sources well, and in local runs it stores about 100,000 documents an hour. This post walks through how it is built, the decisions behind it, and the things that broke along the way.</p>
<hr />
<h2>The one rule: PostgreSQL is the whole system</h2>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/07-postgres-whole-system.png" alt="Drishti, the indexer and the search API all talk only to PostgreSQL" style="display:block;margin:0 auto" />

<p>The design starts from one constraint. Developer's Eye has to be cheap to run and easy for anyone to self-host. The live demo runs on a free-tier Oracle instance. That rules out a separate message queue, a Redis cluster or a coordination service. ( gotta be cheap )</p>
<p>So Drishti ( the crawler) , the indexer , and the search API are three processes follow one source of truth <code>POSTGRES</code> and never call each other directly . Besides postgres lots of built in feature it also keeps coordination (leases, politeness) atomic inside single SQL statements.</p>
<p>The crawler fetech and writes a document in db , indexer notices which documents are new or stale. The API reads the index. Every piece of coordination, from the job queue to per-host rate limits, is a table and a carefully written SQL statement.</p>
<p>This turns out to be a much stronger MVP foundation than it sounds, as long as you respect a few rules about transactions.</p>
<hr />
<h2>The pipeline at a glance</h2>
<p>Each URL moves through the same stage</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/08-pipeline.png" alt="Source registry, frontier, scheduler, policy coordinator, pinned fetcher, parser, processor and writer" style="display:block;margin:0 auto" />

<p>The crawler is asynchronous Python built on <code>asyncio</code> and HTTPX. Each stage is its own package with its own docs and tests. Every major decision has a written ADR, every outage has an incident report, and every performance claim links to the benchmark that produced it.</p>
<h2>The frontier is the job queue</h2>
<p>There is no RabbitMQ or SQS. The <code>crawl_target</code> table is the queue (ADR-0004).</p>
<p>Source registry follows a schema which contains <code>crawl_interval_seconds</code> , <code>priority</code> , <code>max_depth</code> , <code>allowed_hosts</code> configs. Seed discovery adds the seed URLs as targets and store the record in a database table <code>crawl_target</code></p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/09-claim-target.png" alt="claim_target() and the scheduler's job queue" style="display:block;margin:0 auto" />

<p>Now schedular check the target from <code>crawl_target</code> table and claim the target , lease it for next step. BUT a lot interesting things happens in mid.</p>
<p>The <code>claim_target</code> query uses <code>SELECT … FOR UPDATE SKIP LOCKED</code> prevents workers from claiming the same url together.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/10-skip-locked.png" alt="SELECT … FOR UPDATE SKIP LOCKED: only one worker gets each row" style="display:block;margin:0 auto" />

<h3>The deadlock</h3>
<p>But while applying a more interesting thing happened. DEADLOCK. Basically right now two workers cant hold same target together. But suddenly my crawler started throwing <code>DeadlockDetected</code> errors. Why?</p>
<p>Suppose worker 1 locked link X . and waiting for other link Y and worker 2 locked link Y and waiting for other link X , both sides awaits someon to finish their job and unlock the target but nobody unlocks it thinking other is using it. Postgres catches this circle and kills one of the two transactions, so that worker's job fails and the page it fetched is lost.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/11-deadlock-diagram.webp" alt="Two workers each hold one lock and wait for the other's" style="display:block;margin:0 auto" />

<img src="https://nish-chup-one.vercel.app/writing/drishti-1/12-before-deadlock.webp" alt="Before the deadlock: two workers share a task list" style="display:block;margin:0 auto" />

<img src="https://nish-chup-one.vercel.app/writing/drishti-1/13-deadlock.webp" alt="Deadlock: each worker holds the tool the other needs" style="display:block;margin:0 auto" />

<h3>How it was fixed</h3>
<p>Consistent lock order (commit): in <code>enqueue_targets</code> , targets are deduplicated by <code>source_id</code> and <code>normalized_url</code>. And they are sorted by the same key which matches the unique index before the insert.</p>
<p>The lock ( <code>pg_advisory_xact_lock</code> ) is added in sorted <code>source_id</code> order. A conflicting transaction blocks until the other commits, then its insert becomes a no-op. In simple word, every worker locks links in the same sorted order, so nobody waits in a circle. If it still fails it retries</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/14-deadlock-solution.png" alt="The fix: take the tools in the same order, one worker waits its turn" style="display:block;margin:0 auto" />

<h2>Implementing the algorithm in real life</h2>
<p>HOW it claims a target , here comes engineering part.</p>
<p>It uses round-robin algorithm and priority based BFS ( breadth first search ) algorithm.</p>
<h3>How I came up with this decision</h3>
<p>Version 1: priority only.</p>
<p>Initially crawler had 5 source ( MDN {huge } , <a href="https://python.org">python.org</a> , fastapi doc , django doc , rust book ) was supposed to use priority based BFS only but when i inspect the fetching i noticed it was only crawling the first source (MDN) from source registry. No matter how many worker I send all were claiming MDN. The investigation found</p>
<ul>
<li>In source config there was priority set up and it wasnt even calculated</li>
<li>I wasnt using depth to calculate BFS</li>
</ul>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/15-source-starvation.png" alt="Source starvation: every worker crowds around MDN while other sources wait" style="display:block;margin:0 auto" />

<p>The core query was</p>
<pre><code class="language-sql">WHERE (
  Status = queue          | satisfied still not leased
  next_fetch_at &lt;= now()  | satisfied fetch time arrived
)
ORDER_BY(
  Priority.desc ,         | ‼️no priority so skip
  next_fetch_at.ASC       | in the same fetch time this one comes first
  Id ASC                  | go for the first one
)
</code></pre>
<p>AS there was no priority all were going for the first one causing source starvation.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/16-round-robin-bfs.webp" alt="Round robin across sources plus priority-based BFS inside each source" style="display:block;margin:0 auto" />

<p>Version 2: round robin across sources, then priority-based BFS inside the source</p>
<p>Medicine :</p>
<ol>
<li>ROUND ROBIN ( give all source a chance to shine regardless of priority )</li>
<li>use the priority from the source config (a priority calculator basic model exists but is not wired in yet )</li>
<li>use the calculated depth for BFS</li>
</ol>
<p>Now the whole algorithm is priority based BFS + round robin , in short go by priority first then visit shallowest possible page still give less claimed target a little chance.</p>
<p>The updated code was :</p>
<p>Round robin</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/17-round-robin.webp" alt="Round robin" style="display:block;margin:0 auto" />

<pre><code class="language-sql">SELECT s.id
FROM source s
WHERE s.is_enabled = TRUE
  AND EXISTS (
    SELECT 1
    FROM crawl_target ct
    WHERE ct.source_id = s.id
      AND ct.state = 'queued'
      AND ct.next_fetch_at &lt;= NOW()
  )
ORDER BY
    s.last_claimed_at ASC NULLS FIRST, -- WHOEVER IS STARVING
    s.id ASC;
</code></pre>
<p>Priority based BFS</p>
<pre><code class="language-sql">SELECT ct.*
FROM crawl_target ct
WHERE ct.source_id = :source_id
  AND ct.state = 'queued'
  AND ct.next_fetch_at &lt;= NOW()
ORDER BY
    ct.priority DESC, -- famous kid first
    ct.depth ASC,     -- BFS go shallowest depth not too deep
    ct.next_fetch_at ASC,
    ct.id ASC
LIMIT 1
FOR UPDATE SKIP LOCKED;
</code></pre>
<blockquote>
<p>THIS CODES WERE PREVIOUS VERSION, WHILE UPDATING THE QUERY ALSO CHANGED</p>
</blockquote>
<h3>Removing a lock made it 8× faster</h3>
<p>Before (commit <code>e019701</code>)</p>
<p>In Version 2 round robin was picking a source and locking it. Then taking the targets from that source and update the <code>last_claimed_at</code> inside the loop.</p>
<pre><code class="language-sql">-- pick the next source in round-robin order, and LOCK it
SELECT s.id FROM source s
WHERE ... has due targets ...
ORDER BY s.last_claimed_at NULLS FIRST, s.id
FOR UPDATE OF s SKIP LOCKED;

-- then take targets from that source
SELECT ct.* FROM crawl_target ct
WHERE ct.source_id = :sid ...
ORDER BY ct.priority DESC, ct.depth, ...
FOR UPDATE SKIP LOCKED;

-- and update source.last_claimed_at inside the loop
</code></pre>
<p>Why that killed throughput</p>
<p>Take the benchmark case: 1 source with 2,000 due targets and 8 workers.</p>
<ol>
<li>Worker 1 locks the source row and starts claiming.</li>
<li>Workers 2–8 run the same query. The only source is locked, <code>SKIP LOCKED</code> skips it, and there’s no other source left, so they return nothing.</li>
<li>They loop and try again, and get nothing again.</li>
</ol>
<p>So only one worker could claim at a time, even though 2,000 targets were waiting. The other 7 burned transactions on empty claims, about 12,000 of them, and that wasted work also slowed the worker that was claiming. More workers meant more empty round-trips, which is why 8 workers (66–70/s) were slower than 1 (136–143/s).</p>
<ol>
<li>Read the source order without locking it.</li>
</ol>
<pre><code class="language-sql">SELECT s.id FROM source s
WHERE s.is_enabled AND &lt;has a due target&gt;
ORDER BY s.last_claimed_at ASC NULLS FIRST,  -- whoever is starving
         s.id ASC
LIMIT :limit;                                -- no FOR UPDATE
</code></pre>
<p>Every worker gets the same list, and nobody is blocked.</p>
<ol start="2">
<li>Rotate through sources in memory. The ids go into a queue. Take the front source, claim one URL from it, then put it at the back of the line: MDN → python → fastapi → MDN → … A source with nothing left drops out.</li>
<li>Lock only the URL.</li>
</ol>
<pre><code class="language-sql">SELECT * FROM crawl_target
WHERE source_id = :source AND state = 'queued' AND next_fetch_at &lt;= now()
ORDER BY priority DESC,        -- famous kid first
         depth ASC,            -- BFS: shallowest first
         next_fetch_at, id
LIMIT 1
FOR UPDATE SKIP LOCKED;        -- busy URL? take the next one
</code></pre>
<p>The worker leases that row and calls <code>flush()</code> right away. <code>SKIP LOCKED</code> only skips rows locked by other transactions, so without the flush the same worker could grab the URL it had just taken.</p>
<ol start="4">
<li>Record the turns once, at the end, in sorted order.</li>
</ol>
<pre><code class="language-sql">UPDATE source
SET last_claimed_at = GREATEST(last_claimed_at, :claimed_at)
WHERE id = :source_id;   -- run for each source, ascending id
</code></pre>
<p>Updating in id order is the same trick that fixed the deadlock: everyone takes locks in the same order, so no cycle can form. <code>GREATEST</code> stops a late commit from moving a source’s turn backwards.</p>
<p>Now 8 workers on one source each take a different URL, in parallel:</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/18-source-vs-url-lock.png" alt="Lock the source and one worker works. Lock the URL and all eight do." style="display:block;margin:0 auto" />

<table>
<thead>
<tr>
<th>Worker</th>
<th>Source list</th>
<th>URL claimed</th>
</tr>
</thead>
<tbody><tr>
<td>W1</td>
<td>MDN</td>
<td>#1</td>
</tr>
<tr>
<td>W2</td>
<td>MDN</td>
<td>#1 busy → #2</td>
</tr>
<tr>
<td>W3</td>
<td>MDN</td>
<td>#1, #2 busy → #3</td>
</tr>
<tr>
<td>…</td>
<td>…</td>
<td>…</td>
</tr>
<tr>
<td>W8</td>
<td>MDN</td>
<td>#8</td>
</tr>
</tbody></table>
<p>The numbers, from EXP-0001 (1 source, 2,000 URLs):</p>
<table>
<thead>
<tr>
<th>Workers</th>
<th>With source lock</th>
<th>Without source lock</th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>136–143 targets/s</td>
<td>174–185 targets/s</td>
</tr>
<tr>
<td>4</td>
<td>92–99 targets/s (≈6,500 empty claims)</td>
<td>478–485 targets/s (0 empty claims)</td>
</tr>
<tr>
<td>8</td>
<td>66–70 targets/s (≈12,000 empty claims)</td>
<td>563–580 targets/s (≈0 empty claims)</td>
</tr>
</tbody></table>
<p>With the lock, adding workers made things slower. They spent their time claiming nothing while work sat in the queue. Dropping the lock and relying on target-level <code>SKIP LOCKED</code> fixed it, at the cost of fairness that is best-effort rather than strict.</p>
<h2>If a target fails to crawl, when is it retried?</h2>
<p>Other interesting part. What if a crawl attempt is failed? Thats will not automatically fall into dark hole , it will just be rescheduled for next crawl. But not immediately, it follows a series formula</p>
<pre><code class="language-plaintext">Delay = min( base delay seconds x ( 2^(n-1) ) , cap )
</code></pre>
<p>Suppose we set a cap of = 3600 seconds or 1 hr and Base delay seconds = 60s, N = attempt. Suppose target A failed firsttime , its next schedule will be within 60 sec , then 120 sec , then 240 sec , 480 sec, 960 sec , 1920 sec, 3600 sec , 3600 sec , 3600 sec</p>
<p>It goes like : 1 → 2 → 4 → 8 → 16 → 32 → cap → cap → cap</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/19-backoff.png" alt="Exponential backoff: 60 s, 120 s, 240 s … capped at 1 hour" style="display:block;margin:0 auto" />

<h2>The 7 security gates</h2>
<p>Claiming a URL doesn't mean we fetch it. Every hop has to pass the checkpoint first: allowed host? safe IP (no sneaky localhost)? robots.txt says ok? host not busy? ALL YES → fetch. Unsafe → DENY. Temporary issue → DEFER, try later.</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/20-security-gates.png" alt="Security first: every URL is checked before a single byte is sent" style="display:block;margin:0 auto" />

<ol>
<li>Host policy: The syntax is okay , is target in <code>allowed_hosts</code> list? Any weird character like <code>user:pass@</code> ? if passed YES. not DENY.</li>
<li>DNS policy: The resolved host in host policy’s IP must be public. ocalhost, private network or cloud metadata (<code>169.254.169.254</code>)? DENY. we connect ONLY to the IPs we just checked, so DNS can’t switch us to localhost midway (DNS rebinding).</li>
<li>Robots policy: The urls official allow list robots.txt allows us to crawl this site? No = DENY, robots.txt down = DEFER, no robots.txt = allowed</li>
<li>Politeness policy: one request per host at a time with a gap in between, shared by ALL workers. Got a 429/503? The whole crawler backs off.</li>
<li>One bounded request: a single GET, 15 s timeout, 2 MB max, no auto redirects, no hidden retries.</li>
<li>Redirect policy: 301/302/303/307/308: every redirect is a brand-new URL that runs the whole checklist again (max 5 hops, no https → http downgrade).</li>
<li>Response status: 429/5xx → DEFER and retry later. Anything else → hand it to the parser.</li>
</ol>
<h2>The politeness fix: ~120 → ~4,000 documents/minute (on my local crawl)</h2>
<p>In commit <code>800ab2b</code> we introduced shared politeness. What is politeness? We explained it before, it means dont exhaust a single host too much or it might rate limit you. Thats why every host have a <code>min_interval_seconds</code> = default 2s. Some sites set their own delay in robots.txt with a <code>Crawl-delay:</code> line, but Drishti ignores it and uses a hand-written list of longer gaps instead</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/21-politeness.webp" alt="Politeness: don't keep messaging someone who hasn't answered yet" style="display:block;margin:0 auto" />

<p>Problem:</p>
<ul>
<li>A worker grabbed a URL without checking whether that website was free.</li>
<li>If the website had just been visited, the worker sat and waited for the 2-second gap, holding its slot and doing nothing.</li>
<li>Lots of workers ended up waiting on busy websites while other websites had nobody working on them.</li>
<li>Adding more terminals (processes) didn’t make it faster and polite. Each terminal ignored the others, they were tracking the 2 seconds with their own memory, so they hit the same website together.</li>
</ul>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/22-politeness-problem.webp" alt="Workers standing around because the tools they picked are still busy" style="display:block;margin:0 auto" />

<p>Solution:</p>
<ul>
<li>Workers only grab URLs from websites that are free right now. This is the change that made it fast: no more waiting, so every worker is always fetching something.</li>
<li>All terminals share one rulebook in Postgres. This made it safe to run many terminals at once. More terminals means more speed, and the sites still aren’t overloaded. This part is called Shared politeness</li>
</ul>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/23-shared-politeness.webp" alt="Shared politeness: one rulebook in Postgres, workers only take tools that are ready" style="display:block;margin:0 auto" />

<h2>More workers is not more speed</h2>
<p>I thought: slow crawler? Just add more workers. 8 → 16 → 32 → 64. The speed didn’t move.</p>
<p>Here’s my own benchmark (64 fake websites):</p>
<table>
<thead>
<tr>
<th>Workers</th>
<th>2</th>
<th>8</th>
<th>16</th>
<th>32</th>
<th>64</th>
</tr>
</thead>
<tbody><tr>
<td>pages/s</td>
<td>5.1</td>
<td>14.0</td>
<td>14.8</td>
<td>13.8</td>
<td>12.2</td>
</tr>
</tbody></table>
<p>After 16, more workers made it slower. Why?</p>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/24-more-workers.webp" alt="Adding 100 more workers, and most of them have nothing to do" style="display:block;margin:0 auto" />

<h3>The crawl delay</h3>
<p>Drishti waits 2 seconds between two requests to the same website. That’s the crawl delay, the polite thing to do. So every website can give us about 1 page every ~2.5 seconds, no matter what.</p>
<pre><code class="language-plaintext">max speed ≈ number of websites ÷ 2.5 s
</code></pre>
<ul>
<li>5 websites (my first registry): 5 ÷ 2.5 = ~2 pages/s = ~120 pages/min</li>
<li>332 websites (now): 332 ÷ 2.5 = ~130 pages/s = ~8,000 pages/min max</li>
</ul>
<p>With 5 websites, 32 workers were just standing in line for the same 5 sites. Speed comes from more websites, not more workers.</p>
<h3>The knobs I can turn</h3>
<table>
<thead>
<tr>
<th>Setting</th>
<th>Default</th>
<th>What it does</th>
</tr>
</thead>
<tbody><tr>
<td><code>--concurrency</code></td>
<td>2</td>
<td>Slots: how many URLs one terminal works on at once</td>
</tr>
<tr>
<td><code>--batch-size</code></td>
<td>5</td>
<td>How many URLs it grabs per claim (really <code>min(batch, concurrency)</code>)</td>
</tr>
<tr>
<td><code>--min-interval-seconds</code></td>
<td>2.0</td>
<td>Crawl delay: gap between requests to the same website</td>
</tr>
<tr>
<td><code>--lease-seconds</code></td>
<td>300</td>
<td>How long a grabbed URL is “mine” before it’s given back</td>
</tr>
<tr>
<td><code>--job-timeout-seconds</code></td>
<td>240</td>
<td>Max time for one URL (always 15 s+ under the lease)</td>
</tr>
<tr>
<td><code>DB_POOL_SIZE</code> / <code>DB_MAX_OVERFLOW</code></td>
<td>2 / 2</td>
<td>Database connections per terminal</td>
</tr>
</tbody></table>
<h3>The database limit</h3>
<p>Every terminal opens its own database connections:</p>
<ul>
<li>Pools (<code>DB_POOL_SIZE</code>): How many database connections terminal keeps open. Default 2. If worker needs it , it uses it and returns back.</li>
<li>Overflow (<code>DB_MAX_OVERFLOW</code>): The number of extra connections a terminal may open temporarily when all pool connections are busy. When they’re no longer needed, they’re closed again. Default 2</li>
<li><code>max_connections</code>: The total number of connections Postgres accepts at once, from every program combined. It’s set in <code>postgresql.conf</code>. Once it’s full, any new connection is refused with “too many clients”.</li>
<li>API: The search backend, the FastAPI server the website talks to. Every search a user makes borrows a database connection.</li>
<li>Indexer: The indexer worker, the process that turns new documents into searchable index rows (<code>search_index</code>). Each indexer process uses the default 2 + 2 = 4 connections.</li>
</ul>
<pre><code class="language-plaintext">terminals × (pool + overflow) + API + indexer ≤ max_connections
20 × (2 + 2) + 10 + ...                       ≈ 96 of 100   (benchmark machine)
</code></pre>
<p>Too many terminals and Postgres runs out of connections. (It happened, back before shared politeness.)</p>
<h3>So what actually made it fast?</h3>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/25-what-made-it-fast.webp" alt="The fix list: add more sources, tighten the rules, only take free work" style="display:block;margin:0 auto" />

<ol>
<li>More websites. 5 → 332 hosts raised the ceiling.</li>
<li>Host-aware claims. Workers only grab URLs from websites that are free right now, so nobody waits.</li>
<li>Shared politeness. All terminals follow ONE crawl delay through Postgres, so adding terminals doesn’t make Drishti rude.</li>
</ol>
<p>Result on my local crawl: ~120 → ~4,000 pages/min.</p>
<h2>From bytes to documents</h2>
<p>Drishti ingests four formats through bounded adapters: HTML pages, XML sitemaps, RSS/Atom feeds and JSON APIs. Responses are size-capped, and typed failures let the worker tell unsafe requests, retryable errors and oversized content apart.</p>
<p>Processing is pure and does no I/O (ADR-0019). Content is normalized, classified with explicit rules, and fingerprinted with SHA-256 , every single change of document update the sha code thats how documents change are detected. The writer owns every persistence decision:</p>
<ul>
<li>Exact duplicates are caught by fingerprint.</li>
<li>A feed record never replaces a page that was actually fetched (ADR-0050).</li>
<li>A new content source that wants to replace an existing document has to provide at least as much body text (ADR-0052). This came from a real incident where thin pages and competing sources overwrote good content.</li>
<li>Pages that disappear are marked unavailable instead of deleted (ADR-0011).</li>
</ul>
<h2>Drishti 1.0 by the numbers</h2>
<table>
<thead>
<tr>
<th>Measurement</th>
<th>Result</th>
</tr>
</thead>
<tbody><tr>
<td>Local crawl throughput</td>
<td>~100,000 documents/hour</td>
</tr>
<tr>
<td>Claim throughput, 8 workers on one source</td>
<td>563–580 targets/s</td>
</tr>
<tr>
<td>Politeness-safe fetch rate, 4 processes × 200 hosts</td>
<td>204.5 requests/s, 0 gap violations</td>
</tr>
<tr>
<td>Single-process ceiling (local benchmark)</td>
<td>~60 requests/s</td>
</tr>
<tr>
<td>Indexing with 4 outbox shards</td>
<td>581 documents/s</td>
</tr>
</tbody></table>
<p>These are local benchmarks on developer hardware with synthetic hosts where noted. They are not production capacity claims. The hosted demo deliberately runs one crawler worker on a free tier.</p>
<h2>Known limits</h2>
<p>Drishti 1.0 is honest about what it doesn't do yet. The limits fall into three groups.</p>
<h3>Speed</h3>
<ul>
<li>Websites set the ceiling, not workers. With a 2-second crawl delay per host, the crawler can't go faster than about hosts ÷ 2.5 s. Five hosts cap it near 120 pages a minute, and 332 hosts near 8,000.</li>
<li>One process tops out around 60 requests/s. in local benchmarks, likely Python's single event loop, so scaling past that means more processes, not more slots.</li>
<li>Postgres connections are finite. Each crawler process uses up to 4 (pool 2 + overflow 2), and every process shares one <code>max_connections</code> budget.</li>
</ul>
<h3>What it fetches</h3>
<ul>
<li>No conditional recrawl. It doesn't send <code>ETag</code> or <code>If-Modified-Since</code>, so every recrawl downloads the full page. This was a deliberate deferral (EXP-0015) until validator ownership across redirects and content producers is specified.</li>
<li>Exact duplicates only. SHA-256 catches identical copies. Mirrored or versioned docs need near-duplicate detection such as SimHash or MinHash.</li>
<li>No JavaScript rendering, so single-page-app documentation sites don't crawl fully.</li>
<li>No WARC output, so its crawls can't yet be reused by other archiving tools.</li>
</ul>
<h3>Design</h3>
<ul>
<li>One machine, one database. Nobody else can contribute crawling capacity.</li>
<li>Not installable on its own. Drishti imports the Developer's Eye backend, so it can't run without the whole search engine.</li>
<li>One open incident. Vocabulary lock contention (INC-0032) can still stall document finalization.</li>
</ul>
<h2>What's next: Drishti 2.0</h2>
<p>Drishti 2.0 is an evolution of this crawler, not a rewrite. The plan:</p>
<ol>
<li>Its own repository, still connected to Developer's Eye, so contributors can run the crawler without the whole search engine.</li>
<li>A dedicated advanced control panel for watching and steering crawls.</li>
<li>Node-based, multi-user crawling into a shared database, so contributors can lend machines to the crawl.</li>
<li>Updated crawl policies.</li>
<li>Experimental <code>.onion</code> support, with those links opening only in Tor Browser.</li>
<li>A better quality model that keeps only documents worth indexing.</li>
<li>A sustained target of 10 million pages a week, measured locally before it is promised anywhere else.</li>
</ol>
<hr />
<h2>Get involved</h2>
<img src="https://nish-chup-one.vercel.app/writing/drishti-1/26-contribute.webp" alt="Why are you not contributing yet? Don't forget to leave a star." style="display:block;margin:0 auto" />

<p>Drishti and Developer's Eye are MIT-licensed and built in public. If you're interested in crawlers, search, compression or distributed systems, there is real work here and the reasoning behind every decision is written down.</p>
<ul>
<li>Code: <a href="https://github.com/nishchup489-afk/developers_eye">github.com/nishchup489-afk/developers_eye</a></li>
<li>Live demo: <a href="https://developers-eye.vercel.app">developers-eye.vercel.app</a></li>
<li>Community: Discord</li>
</ul>
<p>Start with the crawler's tech docs in <code>0_tech_docs/crawler/</code>. Every ADR, incident and experiment mentioned in this post is there.</p>
]]></content:encoded></item></channel></rss>