“Design a crawler that discovers and refreshes public web pages for a search index.”
Assume a bounded, authorized crawl scope and 10 million successful page fetches per day. We need URL discovery, scheduling, fetching, parsing, deduplication, and revisit policy. Rendering every page with a full browser and ranking search results are out of scope for the first version.
01. Define what the crawler may fetch
Specify allowed schemes, domains, content types, and size limits. Honor applicable access restrictions and the Robots Exclusion Protocol. Identify the crawler and provide a contact path where appropriate.
RFC 9309 defines robots.txt behavior and notes that the protocol is not an authorization mechanism. A path allowed by robots.txt is not permission to bypass authentication, paywalls, or other access controls.
Start from approved seeds. Bound crawl depth or scope according to the product goal rather than allowing every discovered URL to expand the workload indefinitely.
02. Build a polite scheduling frontier
Group queues by host or another appropriate politeness boundary. Track next-eligible time and concurrent fetch limits. A distributed scheduler must coordinate ownership so several workers do not each apply a full independent allowance to the same host.
Cache robots rules with an appropriate refresh policy and implement status-specific behavior. A network or server failure fetching robots.txt should not be treated as a universal invitation to crawl.
03. Deduplicate without changing meaning
Normalize safe syntactic differences, such as host casing and removal of fragments for ordinary HTTP document fetching. Be conservative with path case, query ordering, and tracking parameters: two similar-looking URLs can have different server semantics.
Keep a durable visited or scheduled key set. A Bloom filter can reduce lookup work, but false positives can suppress unseen URLs. Use it only with an explicit coverage trade-off or verify uncertain decisions against authoritative state.
Detect crawl traps such as unbounded calendars, faceted combinations, and repeatedly generated URLs. Bound redirects and URL length. Content hashes can avoid storing exact duplicates; near-duplicate detection is a separate optional layer.
04. Bound every fetch
Apply connection, read, total-time, decompression, response-size, and redirect limits. Validate resolved addresses and every redirect target so untrusted URLs cannot turn the crawler into a path to private services. Account for DNS changes between validation and connection.
Parse untrusted documents in isolated workers with resource limits. Keep the original fetch metadata, normalized URL, status, timestamp, content hash, and parser version for debugging.
The illustrative ten million daily fetches average about 116 per second. At an average compressed response size of 100 KB, that is roughly 1 TB per day before retries and storage overhead. Host-level constraints and latency determine the required concurrency, not bandwidth alone.
05. Revisit according to value and change
Use an initial conservative revisit policy, then adapt based on observed change frequency, source importance, and crawl budget. Conditional requests using validators can reduce transfer when the server supports them, but a 304 still consumes a request and scheduling capacity.
Handle 429, service errors, and timeouts with bounded backoff and host-level cooldown. Persist retry state and cap attempts. A broken host should not monopolize the frontier.
Use leases for in-flight URLs and make fetch-result writes idempotent. After a worker crash, expired leases can be rescheduled; duplicate fetches may still occur, so exact-once fetching is usually an unnecessary promise.
06. Defend the design
“A host serves infinitely many unique pages.”
Enforce host and path-pattern budgets, detect suspicious growth, and prioritize useful pages. Global worker scaling does not solve an unbounded frontier.
“Most content requires JavaScript.”
Add a selective rendering tier only when its coverage benefit justifies the cost and risk. Preserve resource limits and isolate it from the ordinary fetch pool.
Ignoring host-level scheduling, over-normalizing URLs, treating robots.txt as authorization, or allowing redirects and decompression to escape resource limits.
Sources & further reading
- RFC 9309: Robots Exclusion Protocol.
- RFC 9110: HTTP semantics for redirects and conditional requests.
Architecture, throughput, and response sizes are illustrative.
Coordinate a host’s request budget ↗
Apply atomic admission and regional-budget reasoning to politeness limits.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.