if url not in visited:
visited.add(url)
fetch(url)Show answer
Answer
Source: Hello Interview: Multithreaded web crawler, Java Concurrency in Practice
7 operating systems interview questions on building a concurrent web crawler, each with the correct answer and a full explanation.
if url not in visited:
visited.add(url)
fetch(url)Answer
Source: Hello Interview: Multithreaded web crawler, Java Concurrency in Practice
Answer
Source: Hello Interview: Multithreaded web crawler, LeetCode 1242: Web Crawler Multithreaded
Answer
Source: Hello Interview: Multithreaded web crawler, LeetCode 1242: Web Crawler Multithreaded
Answer
Source: Hello Interview: Multithreaded web crawler, interviewing.io: Anthropic interview questions
Answer
Source: Hello Interview: Multithreaded web crawler, IGotAnOffer: OpenAI coding interview
Answer
Keep the BFS shape, then change four things.
Workers: a fixed pool sized for I/O (tens of workers, or an async loop with a semaphore), pulling from a shared frontier queue.
Dedup: an atomic insert into visited (putIfAbsent or a lock around check and add) done when a URL is enqueued, not when it is fetched.
Termination: a pending counter: increment for each new URL before decrementing for the finished one, and stop when it reaches zero; then send poison pills or close the queue so workers exit.
Failure handling: timeouts per fetch, a retry limit, and an exception in one fetch must still decrement pending.
Follow ups: per host politeness, bounded frontier for memory, and measuring the speedup against the single threaded version.
Source: Hello Interview: Multithreaded web crawler, interviewing.io: Anthropic interview questions, IGotAnOffer: OpenAI coding interview
Answer
Partition by host: hash the host to pick the owning machine, so politeness and robots state stay local and each machine dedups its own URLs.
Routing: a machine that finds a link it does not own sends it to the owner through a queue (Kafka or RPC batches).
Dedup: the owner keeps the visited set, in memory with a Bloom filter in front, or in a shared key value store if machines are stateless.
Failure: consistent hashing so a lost machine moves only its share, and the frontier persisted so work is not lost.
Termination: a global pending count is expensive, so most real crawlers run continuously and track freshness rather than detecting a global end.
Source: Hello Interview: Multithreaded web crawler, IGotAnOffer: OpenAI coding interview
These questions come from the Operating Systems Interview Practice pack in Bertopia.