How the internet worksExhibit 23

How does Google search so fast?

A search engine doesn't search the web when you ask. It searches a list it made earlier: an index of every word and the pages it is on. In our test over 16 classic books, finding a word took 40 milliseconds by reading every page and 0.02 milliseconds with the index.

Try it: search three books, two ways

Load Alice in Wonderland, Moby Dick and Hamlet (1.6 MB of text, 3,755 short pages). Your browser builds an index once, then answers each search twice: by reading every page, and by looking the words up in the index.

Timings depend on your device and browser, so they will not match the figures from our test. Browsers also round their clocks, so each method is repeated and averaged.

The video for this exhibit comes out on YouTube on Friday 12 February. Subscribe so you don’t miss it

The slow way

The obvious way to search is to read. We cut 16 classic books into 43,503 short pages, about two million words. To find the word "whale", our program opened every page and looked for it: 40 milliseconds, for 11.5 MB of text. Google says its index is well over 100,000,000 gigabytes, billions of times bigger. Reading cannot be the answer.

The index

The answer is an index: like the one at the back of a textbook, but for every single word, it lists the pages each word appears on. We built ours once, in about one second; it holds 41,028 different words. Finding "whale" is then a single lookup: 705 pages in 0.0216 milliseconds, about 1,900 times faster than reading in that run.

Two words

"White" is on 593 pages and "whale" on 705. The engine takes both lists and keeps only the page numbers on both: 134 pages, without opening a single page. Common words are the hard case: for "to be or not" the lists are so long that our index was only 29 times faster. A word that appears nowhere is the fastest search of all.

Which comes first

Finding pages is the easy half; ordering them is the hard half. We scored each page so that rare words count more and a short page that is mostly your words beats a long one that mentions them once. Our top result for "white whale" was a ten-word line from Moby Dick. Google looks at many more factors and signals; its first famous one, PageRank, used the links between pages.

Before you ask

The index is built before you ask. Programs called crawlers follow links from page to page and feed what they find into it. That is why a new page can take a while to appear: Google says anywhere from a day or two to a few weeks.

Our timings come from one run on one machine and change from run to run; another run gave about 1,500 times for "whale".

Frequently asked questions

How does Google search so fast?

It does not read web pages when you search. It looks your words up in an index that was built earlier, which lists, for every word, the pages it appears on.

What is a search index?

A list of every word with the pages that contain it, like the index at the back of a book. Google says its index covers hundreds of billions of webpages and is well over 100,000,000 gigabytes.

How does a search engine handle two words?

It takes the list of pages for each word and keeps the page numbers that are on both lists. In our test, 'white' (593 pages) and 'whale' (705 pages) met on 134 pages.

Why doesn't a new page show up in search right away?

Because it is not in the index yet. A crawler has to find the page and add it; Google says that can take from a day or two to a few weeks.

Sources

Last updated

Keep exploring