Projects2 of 7

Threadfern

A concurrent web crawler and searchable metadata index, written in plain Java 17 with no framework.

Threadfern’s public demo, showing a saved crawl of example.com with its status, depth and processing time.
LinkifyMatchday ML

Threadfern crawls a website within strict limits and keeps what it finds: page titles, URLs, status codes and the links between pages. You can start bounded crawls, search the results, check for broken links, revisit earlier runs and export them. The engine is plain Java 17 with no framework; the PostgreSQL JDBC driver is its only runtime dependency. A public demo lets anyone look around without signing in.

2.95×
faster with concurrent workers when the server is slow, in a 13-page microbenchmark
1.00×
no gain when the polite delay between requests is what limits speed
1
runtime dependency: the JDBC driver
500 ms
minimum gap between requests to a site, retries and robots.txt included
Next: How the engine is put together

How the engine is put together

  • Small classes with one job each: a coordinator (Crawler), a Fetcher on java.net.http, Robots, URL normalisation, an HTML parser, JDBC persistence, and account-scoped web commands.
  • A small Node bridge starts the Java engine for each command with a 192 MB heap and streams its output as newline-delimited JSON to the website.
  • Pages are keyed by crawl and URL, and links by crawl, source and target, with a foreign key back to pages.
Next: Concurrency that stays bounded

Concurrency that stays bounded

The pool is a ThreadPoolExecutor whose core and maximum sizes are equal, fed from an ArrayBlockingQueue the same size as the pool. The coordinator submits one breadth-first batch at a time, no bigger than the pool, and it alone touches the visited set, the frontier and the database connection. That gives up some peak throughput in exchange for scheduling you can reason about: no unbounded queues, and no shared mutable state between workers.

Microbenchmark: 13 pages, depth 1, three trials, Java 17
SituationOne workerConcurrentSpeed-up
Server takes 120 ms to answer2,167 ms735 msabout 2.95×
An 80 ms polite delay dominatesn/an/aabout 1.00×
Next: Being a good guest on someone else’s site

Being a good guest on someone else’s site

  • Every request to a site, including robots.txt and retries, passes through one synchronized pacing gate.
  • Retries back off exponentially. A 429 or 503 with Retry-After is recorded and never retried early.
  • Responses larger than 2 MB are cancelled mid-download by a custom body subscriber.
  • robots.txt support is a deliberately conservative subset of RFC 9309: if robots.txt can’t be read, crawling is refused, and a Crawl-delay over 60 seconds stops the run.
  • Redirects go back into the frontier and use up a page slot and a depth level, which stops redirect loops without hidden requests.
Next: Data that’s never half-written

Data that’s never half-written

A page saved without its linksIf the process died between writing a page and writing its links, the index would be quietly wrong.

Each page and its links are written in one JDBC transaction, rolled back on any SQLException. A test against real Postgres 17 checks the unique-violation path and the rollback.

Too many crawls at once across instancesPer-account and global daily limits only work if every instance agrees on the count.

Admission takes a Postgres advisory transaction lock, so instances queue rather than race. Runs that have gone quiet for 15 minutes are marked failed.

Stopping a crawl that’s running elsewhereThe process doing the crawl may not be the one that received “stop”.

Cancellation is a durable flag in the database that the coordinator checks between batches. A client disconnecting or the 10-minute deadline sets it too.

Next: Safe to put on the public internet

Safe to put on the public internet

  • The crawler only talks to public addresses on ports 80 and 443: private, loopback, link-local, carrier-grade NAT and multicast ranges are refused, and the JVM DNS cache is pinned so a hostname can’t swap addresses mid-crawl.
  • Online limits: depth up to 5, at most 100 pages and 8 workers, one active crawl per account, 10 runs per account and 30 overall per rolling day, and a 10-minute cap.
  • Someone else’s crawl ID gets the same “Crawl not found” as one that doesn’t exist, so IDs can’t be probed.
  • The account comes from the verified session, never from the browser, and email verification is checked server-side before every crawl.
  • CSV exports prefix formula-like cells, so a hostile page title can’t run in a spreadsheet.
Next: How it’s tested

How it’s tested

  • A dependency-free test harness runs crawls against an in-process HTTP server and checks peak concurrency, pacing, page caps, retries and timeouts.
  • Database tests run against real PostgreSQL 17. Account-isolation tests prove one account can’t run, list, export or stop another’s crawls.
  • In CI, a Docker end-to-end test runs a crawl, restarts the web container and checks the results are still there.
Next: Limits and next

Limits and next

Where it falls short

  • Deliberately out of scope: a distributed queue, resuming crawls, full-text search, sitemaps, JavaScript rendering and refreshing robots.txt mid-run.
  • The benchmark is a microbenchmark on 13 pages, and no automated browser testing has been done.
  • Account deletion, retention rules, MFA and social sign-in aren’t built yet.

What’s next

  • A custom email sender, account deletion and retention.
  • Distributed rate limits for sign-in, and egress rules at the infrastructure level.
Next: Built with

Built with

Services

Data

Delivery

Bigger tiles are tools I use in more places, across my projects and my job at Payaza.

Next project: Matchday ML