Yelp

Location-Based Reviews

Design a local business directory where people find places near them, read and write reviews, and see a rating they can trust.

Overview

A local review service answers one question most of the time: what is near me that matches what I want? The user sends a location, a search term such as 'coffee' and some filters, and expects a ranked list of businesses in a fraction of a second. Everything else (business pages, reviews, photos) is ordinary read-heavy web serving.

What makes it different from plain text search is the location. A normal database index sorts along one dimension, but "near" needs two (latitude and longitude). The core of the design is a geospatial index: a way to turn a 2D location into keys that a normal index can sort, so a proximity query reads a small part of the data instead of all of it.

The second theme is trust. Reads outnumber writes by about a thousand to one, so the average rating is computed once when a review is written, not on every read, and reviews pass through filtering before they count.

Questions to ask first

  • How many businesses and searches? — 10 million businesses; 200 million searches a day
  • What does a search combine? — A location and radius, optional text and category, filters such as price and open now
  • How fresh must results be? — A new business or edited hours may take a minute to show in search; a new review shows on its page within seconds
  • Where do users search? — Worldwide, mostly in cities, so business density varies a lot
  • Are reviews moderated? — Yes: automated filtering decides which reviews count toward the rating

What you will be able to do

  • Explain how geohash, quadtree, S2 and H3 turn 2D locations into indexable keys, and pick one.
  • Walk a proximity query from cells to candidates to exact distance to ranking, including the cell-boundary trap.
  • Keep an aggregate rating correct without recomputing it on every read.
  • Size the system and say why the search index, not the database, is the part to scale.

Key concepts

  • Geohash
  • Quadtree
  • S2 and H3 cells
  • Neighbor cells
  • Haversine distance
  • Bounding box
  • Search index
  • Pre-computed ratings
  • Smoothed average
  • Review filtering

Functional requirements

  • Search businesses near a location, with text, category, price and open-now filters
  • Show a business page: details, hours, photos and reviews
  • Write one review per business, with 1 to 5 stars and text
  • Show an aggregate rating and review count on every result
  • Upload photos for a business

Non-functional requirements

  • Search responds in under 200 ms at p99 (a target we chose)
  • Business pages respond in under 100 ms at p99 from cache (a target we chose)
  • A new review appears on the business page within seconds; search ranking may lag by a minute
  • Read paths stay up if the review pipeline is down (degraded freshness, not an outage)
  • Ratings reflect only reviews that pass filtering

Interview questions

  • How do you find businesses within 1 km of a user?
  • Why not just index latitude and longitude?
  • Geohash, quadtree, S2 or H3?
  • How do you keep the average rating correct and fast?
  • How does search stay fresh when businesses change?
  • What happens in a very dense area like downtown Manhattan?
  • How would you scale this to many regions?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio