Book Deep Read · ML System Design Interview · Chapter 9

Similar Listings: you think it looks for lookalikes — it looks for substitutes

Machine Learning System Design Interview · Ch 9 · Ali Aminian & Alex Xu · 2023

中文 →

What is this chapter about?

You open a place to stay on a rental site, scroll down, and there is always a row of "you might also like." This chapter is about how that row gets picked.

A strange thing first

You probably assume it hunts for places that resemble the one you are viewing — same neighborhood, same two bedrooms, same $120 a night. Filter that way and the results mostly go unclicked.

Meanwhile two places whose specs differ quite a bit — one $120 and one $150, one a whole apartment and one a room in the host's home — get compared back and forth by the same crowd of people, who eventually book one of them. Those two are the genuinely similar pair, because in real people's heads they are interchangeable.

So the pivot in this chapter is: what counts as similar is not decided by the property's specs, it is decided by the people looking at it.

Why the old way is hard

Nobody ever wrote down the answer. Across millions of listings there is no table anywhere saying "A and B are similar." Label them by hand? The number of pairs is astronomical; you could label for a lifetime and not finish.

Computing similarity from the specs drops you straight back into the first trap. Two places can both be "two bedrooms, $120, city center" while one opens onto a subway entrance and the other is a twenty-minute climb uphill. How good the photos are, how it actually feels to stay there — none of that fits in a spec sheet, and that is exactly what people decide on.

The core idea: let browsing trails define similarity

The platform is already sitting on an answer — everyone's browsing trail. The seven or eight places one person opened in a single evening are precisely the set they were weighing against each other. A big platform collects hundreds of millions of such trails.

So give every listing a name card: a short string of numbers the machine works out for itself. One rule only: listings that keep showing up in the same shopping trip get cards that sit close together; two listings picked at random get pushed apart. Run hundreds of millions of trails through that, and the cards that end up near each other belong to places real people actually compare.

It is a bit like inferring who is friends with whom from a pile of group photos. You never ask anyone; you just notice who keeps turning up in the same frame.

There is one extra move. If a trail ends in an actual booking, the booked place gets a say over the whole trail — every place seen along the way is nudged toward it. Because "finally chose it" carries far more weight than "clicked on it."

What about brand-new places?

A listing that just went up has no visitors and therefore no card. The fix is crude and effective: take a few nearby places of the same type and price, average their cards, and use that as a stand-in until the new listing has trails of its own.

What it costs

It can only repeat back what people already look at — a great place nobody has clicked is hard for it to surface, so the cold stay cold and the hot get hotter.

One line to remember

Similar listings are not "the ones that look alike," they are "the ones you'd take instead." And that second thing doesn't need defining — it is already sitting in millions of browsing trails. Pour the trails in and similarity surfaces on its own.

Want the mechanisms, notation and diagrams? → Switch to the deep read