Design a Distributed Web Archiver with Untrusted Workers
System DesignModel answerLast updated
Design a fault-tolerant system that crawls and versions a large wiki using one coordinator, thousands of unreliable workers, and durable blob storage.
The Problem
Build a distributed archiving system that captures and preserves the full content of a large public wiki — think millions of interlinked pages — and keeps that archive up to date over time.
You have three classes of resources:
- One coordinator node that is reliable and always available. It manages metadata but cannot route every page body through itself.
- ~1,000 worker bots that are unreliable and untrusted. They have distinct IP addresses, may crash mid-task, may lie about results, or may return corrupted content.
- Persistent blob storage (think S3-compatible object store) for durable content.
Your goal is a versioned archive: when a page changes, a new snapshot is stored alongside the old ones rather than overwriting them. Focus on the internals of the archiving pipeline, not on building a reader-facing website.
What to Cover
- Discovery and frontier management — how you find pages and track what still needs crawling, given the frontier is too large to hold in memory.
- Deduplication — avoiding redundant fetches and redundant stored blobs.
- Task assignment and lease management — how work is handed out to workers and reclaimed when they fail.
- Worker validation and trust — defenses against workers that return garbage, fabricated content, or partial results.
- Storage and versioning — how content is written, addressed, and published atomically.
- Recrawl scheduling — keeping content fresh without wasting bandwidth.
- Coordinator recovery — what happens if the coordinator restarts.
Constraints and Assumptions
- Workers can disappear at any point, retry a task without telling anyone, or submit results for tasks they were never assigned.
- The coordinator tracks metadata (URLs, state, checksums, lease expiry) but page bodies flow directly from workers to blob storage.
- Pages link to other pages; the link graph is not known ahead of time.
- Crawling must respect the site's robots policy and rate limits.
- A snapshot is only marked "published" after its content and provenance have been verified.
- Decide for yourself whether to use official data dumps or APIs to bootstrap coverage; justify the trade-off.
Hints
Hint 1
Start with frontier state: each URL needs a lifecycle — unseen, leased, done, failed. What data structure backs that at scale, and how does it survive a coordinator restart?
Hint 2
Leases are your primary tool against worker failure. Think about what happens when a lease expires: who detects it, how is the task re-queued, and how do you avoid two workers publishing conflicting results for the same URL?
Hint 3
Untrusted workers need more than a timeout. Consider content hashing, cross-worker redundancy for suspicious results, and what a 'validation gate' looks like before a snapshot is promoted to published.
Model answer
Easy Try it yourself first — then compare your approach, complexity and edge cases.
Approach
A strong answer organizes the system into four concerns: frontier management, work dispatch, result validation, and storage. Then it layers in recrawling and failure recovery.
Bootstrapping and Discovery
The fastest path to full coverage is to seed from the wiki's official data dump (typically XML or Parquet exports updated weekly). This avoids hammering the live site for bulk initial content. Crawling then fills two roles: catching pages newer than the dump, and recrawling for freshness.
The link graph is discovered incrementally. When a worker processes a page, it extracts outbound links and submits them back to the coordinator. Unknown URLs are added to the frontier in UNSEEN state.
Respect robots.txt at startup and cache the parsed rules. Assign each worker's IP a per-domain request budget (e.g., one request per second) enforced by the coordinator during task dispatch, not by the workers themselves — workers are untrusted.
Frontier at Scale
The frontier will have tens of millions of entries. It cannot live in memory alone. Back it with a durable key-value store (Redis with AOF persistence, or a lightweight SQL table) keyed by canonical URL. Each row carries:
state:UNSEEN | LEASED | DONE | FAILEDlease_expires_at: UTC timestampassigned_worker: worker IDattempt_count: for retry budget enforcementcontent_hash: SHA-256 of the last stored body, for change detection on recrawl
Canonical URLs are normalized (scheme, lowercase host, sorted query params, fragment stripped) before insertion to avoid duplicate entries for the same logical page.
Task Assignment and Leases
The coordinator issues leases, not permanent assignments. A lease is a time-boxed promise: "worker W has until time T to deliver a result for URL U." A typical lease TTL might be 5 minutes, long enough for a slow fetch but short enough that a crashed worker doesn't stall a URL for long.
A background sweep on the coordinator scans for rows where state = LEASED AND lease_expires_at < now(). Expired leases are reset to UNSEEN (or FAILED after N attempts). This sweep runs every 30–60 seconds.
Workers pull tasks in batches rather than one at a time, reducing coordinator load. Batch size is tuned to the target crawl rate and per-domain pacing rules.
Dealing with Untrusted Workers
This is the most interesting part of the design. Several layers of defense:
Content hashing. Workers upload the raw page body to blob storage using a pre-signed URL, then report the SHA-256 to the coordinator. The coordinator (or a small validator service) downloads and independently hashes a sample — say 5% of submissions. Mismatch triggers a full re-fetch by a different worker.
Schema and format validation. The page body is parsed: valid HTML/wikitext, expected encoding, reasonable size bounds. A 3-byte response or a body that is pure JavaScript with no article content fails validation.
Redundant fetching for suspicious results. Any submission that fails a spot check, or comes from a worker with a degraded trust score, gets independently re-fetched by a second worker before publication. Agreement on content hash is required.
Worker trust scores. Track each worker's historical accuracy (validated submissions / total submissions). Workers below a threshold get their results quarantined until verified. Persistent bad actors are banned by worker ID.
Idempotent submission. Workers may submit the same result more than once (e.g., network retry). The coordinator accepts a submission only if the task is currently in LEASED state assigned to that worker, making re-submissions safe no-ops.
Storage and Versioning
Page bodies are stored content-addressed: the blob key is derived from the content hash (e.g., blobs/<sha256-prefix>/<sha256>). This naturally deduplicates identical content across versions.
A separate manifest record in the coordinator's store maps (canonical_url, version_timestamp) to a blob key. This keeps version history cheap — only a pointer, not a copy of the body.
Publication is a two-phase write:
- Blob is written to object storage (idempotent; content-addressed writes are safe to retry).
- Coordinator atomically updates the manifest and sets
state = DONE.
If the coordinator crashes between steps, the blob exists but state stays LEASED. After lease expiry the task is retried. The second worker writes the same blob (same key, same content) and completes the manifest write. No corruption, no duplication.
Recrawl Scheduling
Not all pages change at the same rate. Schedule recrawls using exponential backoff seeded by observed change frequency: a page that changed every 7 days gets a 7-day recrawl interval; one unchanged for 6 months gets a 90-day interval, capped at some maximum.
On recrawl, use HTTP conditional requests (If-None-Match with the stored ETag, or If-Modified-Since) to avoid re-downloading unchanged content. A 304 response updates the last_checked timestamp without writing a new blob.
Media assets (images, audio, video) are a separate typed crawl with its own priority queue and bandwidth budget — treating them the same as article text would flood the bandwidth budget.
Coordinator Recovery
The coordinator's metadata store is the single point of truth. It needs:
- Synchronous replication or WAL-based durability (no in-memory-only state).
- A periodic full snapshot exported to blob storage as a recovery artifact.
- On restart, lease sweep runs immediately to reclaim any tasks that were in-flight.
If the coordinator is down for a period shorter than the minimum lease TTL, no work is lost. Workers that finish during the outage will retry their submission once the coordinator is back.
Common Mistakes
- Trusting worker-reported checksums without verification. Always validate at least a sample independently.
- Storing page bodies on the coordinator. At scale this creates a bandwidth bottleneck; bodies go directly to blob storage.
- Infinite retries. Always cap attempt count and route exhausted tasks to a dead-letter queue for manual inspection.
- Ignoring robots.txt pacing. Rate limiting must be enforced centrally; per-worker enforcement is unenforceable given untrusted workers.
- Forgetting the coordinator is a single point of failure. Durable metadata storage and fast recovery are not optional.