Preparing your design workspace

Loading the problem and your saved attempt…

Design and Implement a Concurrent Web Crawler Library

Coordinate bounded parallel fetching, exact URL admission, cancellation, and race-safe session completion in one process.

Design and implement the concurrency and lifecycle core of an in-process web crawler around a provided PageFetcher. For this exercise, assume a caller supplies one absolute seed URL, a concurrency limit from 1 through 32, and a maximum of 10,000 admitted pages. The fetcher returns normalized absolute outgoing links for one URL or a typed fetch failure. Admit same-origin links only, reserve each normalized URL at most once before queueing it, and start no more than the configured number of fetches concurrently. Record successful URLs and one terminal failure per failed URL; do not retry. A start call returns a CrawlHandle whose completion eventually yields one immutable CrawlResult and whose cancel operation is idempotent. Cancellation prevents queued or newly discovered work from starting, permits already-running fetch calls to finish, discards links they return, and completes after the running count reaches zero. Without cancellation, complete exactly once when both the frontier and running count are empty. Fetch calls must occur outside the state lock, and the injected executor must never invoke submitted work inline. Use injected fetching and execution boundaries so concurrency-limit, duplicate-discovery, failure, cancellation, and completion races can be tested without sleeps. HTTP parsing, robots.txt, authentication, persistence, distributed crawling, redirects, retries, ranking, and politeness delays are out of scope.