An algorithm is just a piece of code that solves a problem. Facebook's problem, with the News Feed, is that each day, there are 1,500 pieces of content—news articles, baby photos, engagement updates—and much of it is boring, dumb, or both. Amazon's problem is that it wants you to keep shopping after you buy what you came for, even though you don't need the vast majority of what Amazon's got to sell.

Both organizations narrow the aperture of discovery by using their best, fastest, most scalable formulas to bring to the fore the few things they think you'll want, all with the understanding that, online, you are always half a second away from closing the tab.

Take the News Feed, perhaps the most famous and sophisticated media algorithm ever built. The full recipe of the News Feed is ultimately mysterious, but we have a sense of some of the portions. The most important ingredient is you. When you like something, hide something, click on something, or do nothing, Facebook's machine-learning algorithms considers your activity and bakes it into your next News Feed so that you see more of the stuff you've indicated you like. At the same time, Facebook also allows companies and individuals to pay for promotions to appear toward the top of the feed. Finally, the company routinely adjusts its dials, for example to show more news stories from respectable organizations with large digital followings. The News Feed is a little bit of behavioral psychology, a little bit of capitalism, and little bit of secret sauce.

Amazon's storefront also radically changes for each consumer, showing different pages to a gadget nerd, a romance novel reader, or a new parent. Building a recommendation engine from, not 1500 new stories, but millions of products means processing even more data within the half-a-second of a page load. This leaves little time to draw a personalized data map for each customer.

No algorithm existed to do what Amazon needed to do at the scale Amazon needed to do it. So the company built a unique patented recommendation formula for itself in the late 1990s, as its chief engineer explained. Rather than match customers to similar customers, Amazon built an index of items that customers tend to purchase together. When you check out a page or make a purchase, the site shows you products with high ratings and similar qualities based on that index. Here, scraped from the patent application, is a diagram of how this system works, at the simplest level.

The key to this formula, which goes by the term "item-to-item collaborative filtering,” is that it’s fast, it’s scalable, and it doesn’t need to know much about you. This is a recommendation engine based on products rather than people. At its simplest, that means suggesting a football book to somebody who buys a football video game.