Theme

Interactive diagram · architecture

Design a web crawler

Design a web crawler A crawler pulls ranked links from NoSQL storage, sends indexing and document jobs through queues, and a search request travels through DNS, a load balancer, web server, and Query API to retrieve indexed titles and snippets. Design a web crawler Diagram after donnemartin/system-design-primer · CC BY 4.0 CrawlerService Queue Queue NoSQLDatabase 1 · Crawl pages Reverse IndexService2 · Index words DocumentServiceMemory Cache3 · Build documents ClientDNSLoad BalancerWeb ServerQuery API4 · Search pages
✕

1 · Crawl pages

Crawler Service pulls ranked links, avoids already-crawled pages, and sends follow-on work through two queues.

✕

2 · Index words

The reverse-index queue feeds the service that maps words to the pages that contain them.

✕

3 · Build documents

The document queue feeds the service that creates static titles and snippets for pages.

✕

4 · Search pages

A client request reaches Query API, which uses the reverse index and document service to return relevant pages.

✕

Client

Step 4 · Search pages

What it is

The user enters a search term and sees relevant pages.

Its job here

It asks DNS where to connect, then sends the search request to Load Balancer. It receives titles and snippets in the result.

In the primer

Domain name system →

✕

DNS

Step 4 · Search pages

What it is

DNS resolves a name so the client can find the service.

Its job here

It receives the lookup from Client and gives back the connection destination. Client then sends its request to Load Balancer.

Trade-off

DNS is an extra dependency before the request reaches the crawler system.

In the primer

Domain name system › Disadvantages →

✕

Load Balancer

Step 4 · Search pages

What it is

A load balancer distributes incoming requests across service instances.

Its job here

It receives the search request from Client and passes it to Web Server. The stacked copies show that it can have several instances.

Trade-off

It adds another component to operate before requests reach Web Server.

In the primer

Load balancer › Horizontal scaling →

✕

Query API

Step 4 · Search pages

What it is

The public REST API parses a search query.

Its job here

Web Server forwards the request here. Query API uses Reverse Index Service, then Document Service, to return matching pages with titles and snippets.

Trade-off

Query parsing adds work before results can be returned.

In the primer

Communication › REST →

✕

Document Service

Step 3 · Build documents

What it is

This service creates static titles and snippets for pages.

Its job here

Document Queue delivers crawl jobs to it. It passes page documents to Memory Cache and Query API uses it to return titles and snippets.

Trade-off

Titles and snippets are static and do not change for each query.

In the primer

Cache › Application caching →

✕

Reverse index queue

Step 1 · Crawl pages

What it is

A queue holds reverse-index jobs.

Its job here

Crawler Service adds a job here after it crawls a link. The queue hands that job to Reverse Index Service.

Trade-off

A queue separates crawling from indexing, so the work does not have to finish in the crawler loop.

In the primer

Asynchronism › Message queues →

✕

Document queue

Step 1 · Crawl pages

What it is

A queue holds document-generation jobs.

Its job here

Crawler Service adds a job here after it crawls a link. The queue hands that job to Document Service.

Trade-off

A queue separates document work from the crawler loop.

In the primer

Asynchronism › Message queues →

✕

Crawler Service

Step 1 · Crawl pages

What it is

The service processes the highest-ranked page link in a loop.

Its job here

It reads ranked links and signatures from NoSQL, then adds jobs to both queues. It writes the crawled link and page signature back to NoSQL.

Examples

  • Jaccard index
  • Cosine similarity

Trade-off

It must detect similar pages so a graph cycle does not become an infinite loop.

In the primer

Database › Key-value store →

✕

Memory Cache

Step 3 · Build documents

What it is

A memory cache keeps generated page documents ready to read.

Its job here

Document Service feeds it with titles and snippets. Query API can use those documents after Reverse Index Service finds matching pages.

Trade-off

Cached data can require an update strategy as pages are crawled again.

In the primer

Cache › When to update the cache →

✕

NoSQL Database

Step 1 · Crawl pages

What it is

A key-value NoSQL database stores links to crawl and crawled links with signatures.

Its job here

Crawler Service reads the next ranked link and checks similar page signatures here. It then removes the link to crawl and inserts the crawled link and signature.

Examples

  • Redis

Trade-off

Choosing SQL or NoSQL depends on the use cases and trade-offs.

In the primer

Database › SQL or NoSQL →

←/→ step · Space play/pause · R replay · Home/End jump

Detail · follows playback, or click any box or step to pin it

Click any box for an explanation, or use Next or Play to walk through the four steps.

1 · Crawl pages

Crawler Service pulls ranked links, checks crawled signatures, and sends indexing and document jobs through queues.

It stores processed links and signatures in NoSQL.

2 · Index words

Reverse Index Service creates the map from words to the pages that contain them.

The queue lets indexing run separately from crawling.

3 · Build page documents

Document Service creates static titles and snippets for pages.

Generated documents are ready for a later search response.

4 · Search pages

Client reaches Query API through DNS, Load Balancer, and Web Server.

Query API uses the reverse index and page documents to return relevant pages.