Google Search System Design
Crawl, index and serve the web: how a search engine is built
By Ankur NayakReviewed
How a web search engine works, from Google's own documentation and its founding paper: Googlebot discovers and fetches billions of pages, renders them with a recent Chrome, indexing clusters duplicates and stores signals in an index spread over thousands of computers, and serving ranks matches using hundreds of factors. The 1998 prototype's pipeline is shown as a historical layer.
Open in Studio· edit a copy- Storage
- Index on thousands of computers
- Pages crawled
- Billions
- Ranking factors
- Hundreds
- Caffeine: fresher results
- 50%
- 1998 prototype
- 24M pages
Requirements
Functional
- Discover new and changed pages across the web
- Fetch and render pages, including ones built with JavaScript
- Group duplicate pages and pick a canonical one to show
- Return the most relevant, high-quality results for a query in a fraction of a second
- Tailor results to the user's language, location and device
Non-functional
- Crawl politely: never overload a website
- Freshness: new content searchable quickly
- Index billions of pages across thousands of machines
- Low query latency at enormous query volume
In depth
Three stages
"Design a search engine" and "design a web crawler" are classic interview questions, and Google is the natural reference. Google doesn't publish the internals of today's Search, but it does document how the system works at the level of its stages, and the 1998 paper by Sergey Brin and Larry Page describes the original prototype in detail. This page uses both, keeping the historical design clearly labelled.
According to Google's guide, Search works in three stages, and not every page makes it through each one:
- Crawling: automated programs download text, images and videos from pages found on the web.
- Indexing: Google analyses what it downloaded and stores it in the Google index, a large database.
- Serving: for each query, Google returns the information it judges most relevant.
Crawling: discovery and politeness
There is no central registry of web pages, so Google must constantly look for new and updated ones, a process it calls URL discovery. Most new pages are found by following links from pages it already knows: a blog's home page links to a new post. Site owners can also submit a sitemap, a list of pages to crawl.
The program that fetches pages is Googlebot, running on a huge set of computers that crawl billions of pages. An algorithmic process decides which sites to crawl, how often, and how many pages to fetch from each; not every discovered page is crawled.
Crawling must be polite. Googlebot tries not to crawl a site so fast that it overloads it, and it sets its rate from the site's responses: HTTP 500 errors mean "slow down". Google also says plainly that it doesn't accept payment to crawl a site more often.
Modern pages are often built by JavaScript, so during the crawl Google renders each page and runs its scripts using a recent version of Chrome, much as a browser would.
Indexing: understanding pages
Indexing processes each page's text and key tags and attributes, such as the <title> element and alt text, along with images and videos. Two jobs stand out.
The first is duplicate handling. The same content often appears at many URLs. Google groups similar pages, a step it calls clustering, and selects the one most representative of the group as the canonical, the version that may appear in results. The others are kept as alternates that may be served in different contexts.
The second is collecting signals about the canonical page and its content, such as its language, the country it is local to, and its usability. These feed serving. The result is stored in the Google index, a large database hosted on thousands of computers. Indexing isn't guaranteed: not every page Google processes is indexed.
Serving: ranking
When someone searches, Google's machines look up matching pages in the index and return the results judged highest quality and most relevant. Relevance depends on hundreds of factors, including the user's location, language and device. A search for "bicycle repair shops" shows different results in Paris than in Hong Kong. Ranking is programmatic, and Google doesn't accept payment to rank pages higher.
Freshness: Caffeine
In June 2010 Google finished rolling out a new index called Caffeine. The previous index had several layers, some refreshed faster than others; the main layer updated every couple of weeks, so refreshing it meant analysing a large part of the web at once. Caffeine instead analyses the web in small portions and updates the index continuously, so new content can be searchable as soon as it is found. Google said it gave 50% fresher results. At the time it processed hundreds of thousands of pages per second in parallel, and occupied nearly 100 million gigabytes of storage in one database.
The historical layer: the 1998 prototype
The drill-down in the diagram shows the original architecture from "The Anatomy of a Large-Scale Hypertextual Web Search Engine", which indexed a crawl of 24 million pages. It is still the clearest picture of how an inverted index search engine fits together:
- A URLserver sent lists of URLs to the crawlers (typically about three, written in Python). Each crawler kept roughly 300 connections open and its own DNS cache, since DNS lookups were a major bottleneck.
- A storeserver compressed fetched pages into the repository, each page getting a docID.
- The indexer parsed pages into hits (word, position, font size, capitalisation), wrote them into 64 barrels as a partially sorted forward index, and saved links into an anchors file.
- The URLresolver turned anchors into docIDs and built the links database used to compute PageRank.
- The sorter re-sorted the barrels by wordID into the inverted index; four machines did it in about 24 hours. DumpLexicon built the lexicon the searcher used.
- The searcher, run by a web server, answered queries using the lexicon, the inverted index and PageRank.
The whole 24-million-page index could be built in under a week. Today's system is vastly larger and different in detail, but the pipeline (discover, fetch, store, parse, invert, rank, serve) is the same shape every search engine follows.
The trade-offs
Continuous indexing buys freshness at the cost of an index that is always changing. Rendering JavaScript sees what users see but costs far more than parsing HTML. Picking one canonical per duplicate group saves storage and improves results, but the chosen page may not be the one the owner wanted. And politeness means struggling sites are indexed later.
For another Google system at the same scale, see YouTube; for how Google keeps data consistent across continents, see Spanner.
What to take into an interview
- Split the design into crawl, index and serve, each scaled independently
- Keep a URL frontier fed by links and sitemaps, with per-site politeness
- Render pages when content depends on JavaScript
- Deduplicate and choose canonicals before indexing
- Build an inverted index sharded across many machines; rank with many signals
- Prefer incremental index updates to periodic rebuilds when freshness matters
Components
Person Searching
Client. Types a query on a desktop or phone.
Websites
External API. Billions of pages, with no central registry. New ones are found through links from known pages and through sitemaps that site owners submit.
Crawl Scheduler
Scheduler. An algorithmic process decides which sites to crawl, how often, and how many pages to fetch from each. Not every discovered page is crawled.
Googlebot
Worker. The crawler fleet that fetches pages. It adjusts its rate to each site's responses so it doesn't overload it.
Why: A crawler that ignores server health would be a denial-of-service attack on the web.
Renderer
Recent ChromeService. Renders each page and runs its JavaScript with a recent version of Chrome, so content added by scripts is seen as a browser would see it.
Indexing
Batch processing. Analyses text, key tags such as <title> and alt attributes, images and videos; clusters similar pages and picks the canonical one; and records signals such as language, country and usability. Indexing isn't guaranteed.
Google Index
Search index. A large database hosted on thousands of computers. Since Caffeine (2010) it is updated continuously in small portions instead of rebuilding a main layer every couple of weeks.
Building block: Inverted Index, Database Sharding
URLserver
Scheduler. Sends lists of URLs to be fetched to the crawlers.
Crawlers (1998)
PythonWorker. Typically about three, each keeping its own DNS cache because DNS lookups were a major bottleneck.
Storeserver
Service. Compresses fetched pages and stores them in the repository.
Repository
Object storage. Every page's compressed HTML, keyed by docID.
Indexer (1998)
Batch processing. Parses each page into hits (word, position, font, capitalisation), writes them into 64 barrels as a forward index, and saves links into an anchors file.
URLresolver
Worker. Turns anchors into absolute URLs and docIDs, and builds the links database used to compute PageRank.
Sorter
Batch processing. Re-sorts the barrels by wordID to produce the inverted index. Four machines sorted everything in about 24 hours.
Building block: Inverted Index
Searcher (1998)
Service. Run by a web server; answers queries using the lexicon, the inverted index and PageRank.
Serving
Service. Searches the index for matching pages and returns the results judged most relevant and highest quality.
Ranking
Service. Relevance is determined by hundreds of factors, including the user's location, language and device. Ranking is programmatic; Google doesn't accept payment to rank pages higher.
Request flows
A new blog post becomes searchable
- A known page, the blog's home page, now links to a new post: a new URL is discovered.
- The scheduler decides it's worth crawling, and when.
- Googlebot fetches the post at a rate the site's responses say it can handle.
- The page is rendered with a recent Chrome and its JavaScript runs.
- Text, title, alt text and images are analysed; duplicates are clustered and a canonical URL picked.
- The page and its signals land in the index; with continuous indexing this needn't wait for a rebuild.
Answer a query
- Someone in Paris searches for 'bicycle repair shops' on a phone.
- The serving system looks up matching pages in the index.
- Hundreds of factors, including location, language and device, order the matches.
- Results local to Paris come back, different from what a user in Hong Kong would see.
Failure scenarios
What if: a website starts returning HTTP 500s?
Googlebot sets its crawl rate from the site's responses. Server errors such as HTTP 500 mean 'slow down', so it backs off rather than adding load to a struggling site.
User impact: The site's new pages are indexed more slowly until it recovers.
- Per-site crawl rate driven by responses
- Retry later rather than hammering
What if: thousands of URLs show the same content?
Tracking parameters, mirrors and printer versions create many URLs for one page. Indexing clusters similar pages and selects one canonical page to show in results; the others are kept as alternates for other contexts.
User impact: None: one result instead of many copies.
- Duplicate clustering
- Canonical selection
Trade-offs
Continuous indexing over periodic rebuilds
Update the index in small portions all the time (Caffeine, 2010) instead of a main layer refreshed every couple of weeks.
- Pros
- 50% fresher results
- New content searchable soon after it is found
- Cons
- An index that is always changing is harder to build and test than a batch one
Render pages like a browser
Run JavaScript with a recent Chrome during the crawl.
- Pros
- Sees content that scripts add
- Matches what users see
- Cons
- Rendering costs far more than parsing HTML
Index one canonical per duplicate group
Cluster similar pages and show one representative.
- Pros
- Less storage, better results
- Cons
- The chosen canonical may not be the one the site owner preferred
Politeness over speed
Let each site's responses limit how fast it is crawled.
- Pros
- Never overloads small sites
- Cons
- Slow or struggling sites are indexed later
Frequently asked questions
How does Google Search work?
In three stages. Crawling: Googlebot discovers URLs through links and sitemaps and fetches pages. Indexing: Google renders and analyses each page, picks a canonical among duplicates and stores it in the index. Serving: for each query, it finds matching pages and ranks them using hundreds of factors.
How would you design a web crawler?
Keep a frontier of URLs, discovered from links and sitemaps, and a scheduler that decides what to fetch and how often. Fetch politely, limiting the rate per site and backing off on server errors; cache DNS; render JavaScript where needed; and feed new links back into the frontier.
What was Google Caffeine?
Caffeine was the search index Google finished rolling out in June 2010. Instead of refreshing a main index layer every couple of weeks, it analyses the web in small portions and updates the index continuously, which Google said gave 50% fresher results.
What did the original Google architecture look like?
The 1998 prototype had a URLserver feeding crawlers, a storeserver compressing pages into a repository, an indexer producing a forward index in barrels, a sorter turning it into an inverted index, a URLresolver building the links database for PageRank, and a searcher answering queries.
Building blocks used
Sources
- In-depth guide to how Google Search works · Google Search Central
- Our new search index: Caffeine · Google Search Central Blog
- The Anatomy of a Large-Scale Hypertextual Web Search Engine · Computer Networks (Brin, Page)