Skip to content

Design Yelp

A system design interview walkthrough for Yelp, a nearby business search service, covering geo indexing, filters, ranking, reviews and read-heavy scale.

Intermediate23 minUpdated 2 December 2026

Before this: Spatial Indexing (QuadTrees & GeoHashing), Search Systems (Elasticsearch)

"Design Yelp" is the standard proximity-search question. A user stands somewhere, types "ramen" or taps "coffee", and expects the best open places nearby, in under a second, with ratings that look right.

The interviewer is not asking whether you know what a map is. They want to see whether you can tell a geometry problem from a search problem. Finding points near a point is the easy half. The hard half is that users combine distance with a category, a price band, "open now" and a minimum rating, and then expect the results sorted by something better than distance.

We will work it the way you should in the room. The basics of cells and trees live in spatial indexing, and the inverted index behind filters lives in search systems. Here we spend our words on the interview design.

Clarify the requirements

Functional requirements:

  1. Search for businesses near a location, by keyword, category and radius.
  2. Filter by price, rating and "open now".
  3. View a business page with its details, photos and reviews.
  4. Write a review with a star rating, and see the business's average update.
  5. Business owners add and edit their listings.

Out of scope, said aloud: photo upload and moderation, reservations, ads, review spam detection, turn-by-turn directions (that is Google Maps).

Non-functional requirements: these decide the architecture.

  • Search is read-heavy and latency-sensitive: results in a few hundred milliseconds, because every search is a user waiting.
  • Business data changes slowly. Restaurants do not move. Opening hours and ratings change, but minutes of staleness are acceptable, so the index can be eventually consistent.
  • Density is wildly uneven. One city block can hold hundreds of restaurants and a rural county holds three. A fixed radius query must work in both.
  • A new review should show up on its own business page quickly, even if the search ranking catches up later.

Estimate the scale

Assume 10 million daily active users, each running 5 searches a day, and 50 million businesses worldwide.

Search reads: 10M × 5 = 50M searches a day ÷ 86,400 ≈ 580 searches per second, and about 1,700 per second at peak (3× average). Page views of business pages add more, but they are lookups by id and cache well.

Writes: assume 1 in 50 daily users leaves a review, so 10M × 0.02 = 200,000 reviews a day ≈ 2.3 reviews per second. Listing edits are far rarer.

Storage: 50M businesses × 1 KB ≈ 50 GB of listing data. Reviews at about 1 KB each: 200,000 × 1 KB = 200 MB a day, which is about 73 GB a year and 365 GB over five years. Photos sit in object storage and are out of scope.

Index size: the search index holds a trimmed copy of each business (id, location, category, price, rating, hours), say 300 bytes: 50M × 300 B = 15 GB. That fits across a few nodes' memory and disk caches.

"2 writes a second against 1,700 searches a second means everything is built for reads. The searchable data is only 15 GB, so I can replicate it freely instead of sharding aggressively. What is hard is the query shape, a location plus filters plus ranking, not the volume."

Change the assumptions in the capacity estimator to watch the numbers move.

API and data model

GET  /v1/search?lat=&lng=&radius=&q=&category=&price=&minRating=&openNow=&cursor=
                                        -> { results[], nextCursor }
GET  /v1/businesses/{id}                -> business, hours, rating summary
GET  /v1/businesses/{id}/reviews?cursor=
POST /v1/businesses/{id}/reviews        { stars, text }   (Idempotency-Key header)
PUT  /v1/businesses/{id}                (owners only)
businesses (id PK, name, lat, lng, cell_id, category[], price, hours, rating_sum, rating_count)
reviews    (business_id PK, created_at + review_id SK, user_id, stars, text)
search index document: { id, location, cell_id, category[], price, rating, open_windows[] }

The non-obvious choice is rating_sum and rating_count on the business row. The average is rating_sum ÷ rating_count, computed on read. Recomputing an average over every review each time one arrives would scan thousands of rows to change one number.

High-level design

The slice worth running is the search path: a load balancer, a stateless search API, a cache keyed by map cell, and a geo-capable search index behind it.

Nearby-business searches pass a load balancer to a search API that checks a cell cache first, then falls back to a geo-indexed business index.clientslbsearch apicell cachebusiness index
Nearby-business searches pass a load balancer to a search API that checks a cell cache first, then falls back to a geo-indexed business index.
  • Clients reach the search API through a load balancer.
  • The API checks a cache of results per map cell, and on a miss queries the business index.
Describe this diagram

Components

  • clients (Client)
  • lb (Load balancer)
  • search api (Service)
  • cell cache (Redis)
  • business index (Search cluster (Elasticsearch))

Connections

  • clients sends to lb
  • lb sends to search api
  • search api sends to cell cache
  • search api sends to business index

Run it, then try taking the cache out or doubling the load. The index nodes are the first thing to feel it.

The read path: the API turns the user's point into a cell id, looks up a cached candidate list for that cell and filter set, and on a miss asks the index for businesses within the radius that match the filters. It ranks the candidates and returns a page.

The write path: a new or edited business goes to the primary database first. A change feed (the database's change stream or an outbox) updates the search index within seconds. A review inserts a row and bumps rating_sum and rating_count in one transaction, then the same feed refreshes the index copy of the rating.

The interesting problem: nearby search with filters

A user searching "coffee within 1 km, open now, 4 stars or better" is asking three things at once. How you combine them is the heart of the answer.

Approach A: SQL with a bounding box

SELECT * FROM businesses
WHERE lat BETWEEN ? AND ? AND lng BETWEEN ? AND ? AND category = 'coffee';

Good: it is one query on a database you already have, and it works for a prototype.

Bad: a B-tree sorts on one dimension, so the database narrows by latitude and then scans a whole band of the planet to filter longitude. Adding a composite index on the other filters does not fix a two-dimensional range.

Approach B: a cell index, then filter

Give every business a geohash or cell id (see spatial indexing). To search, compute the cell holding the user and its eight neighbors, fetch the businesses in those cells, then compute exact distance and apply the filters in memory.

Good: no new infrastructure, cells are cheap to cache, and the neighbor lookup handles the border problem.

Bad: a fixed cell size is wrong somewhere. A cell sized for a village holds 4,000 restaurants in midtown Manhattan, so you fetch thousands of rows to return twenty. A cell sized for Manhattan is empty in a village, and you must widen the search ring by ring.

Approach C: a search index with a geo field

Put each business in a search engine as a document with a geo point, categories, price, rating and opening windows. A query combines a distance filter, the keyword match and the other filters in one pass, and the engine uses its own spatial structure plus inverted-index intersections.

Good: filters and geometry run together, so a rare filter such as "vegan, open now" prunes before any distance math. Relevance scoring comes with it.

Bad: one more system to keep in sync with the database, and the index is eventually consistent.

The recommended answer is C for the query, with B's cells kept for caching. The deciding fact is that real queries are filter-heavy. Name the index as a candidate generator, not a source of truth, then re-rank. Keep the cell id as a cache key: two users standing a few meters apart can share one cached result list, which turns a 580-per-second search load into far fewer index queries. That reasoning, picking the structure by the shape of the query, is what earns credit.

Conceptual diagramhitmissUser point and filtersCell id and filter hashCached candidatesSearch index queryExact distance and rankPage of results
Diagram, as text
  • User point and filters leads to Cell id and filter hash
  • Cell id and filter hash leads to Cached candidates (hit)
  • Cell id and filter hash leads to Search index query (miss)
  • Search index query leads to Cached candidates
  • Cached candidates leads to Exact distance and rank
  • Exact distance and rank leads to Page of results

The second decision: ranking and ratings

Sorting by distance alone sends users to the nearest mediocre place. Sorting by raw average rating is worse, because a business with one 5-star review beats one with 800 reviews averaging 4.7.

The usual fix is a smoothed rating: pull a business's average toward the overall average in proportion to how few reviews it has. A simple form is (rating_sum + k × global_mean) ÷ (rating_count + k), with a small constant k such as 5 to 10. With few reviews the score stays near the global mean, and with many it follows the real average. Combine it with distance and text relevance in a weighted score, and say the weights are tuned by experiment.

Where does the score live? Compute the smoothed rating when the review arrives and store it on the index document. Computing it at query time means a database read per candidate. The cost is that the ranking trails a new review by the index refresh delay, which is acceptable here and is why we separate the business page (read from the database, instant) from the search ranking (read from the index, seconds behind).

Bottlenecks and failures

Hot cells. A downtown lunch hour sends thousands of searches per second to a handful of cells. The cell cache absorbs it, but a single cache node holding that key can saturate. Replicate hot keys or add a short-lived in-process cache on each API server.

Cache fragmentation. A cache keyed by cell and every filter combination fragments into millions of entries with low hit rates. Cache only the common combinations (category plus cell), and apply minor filters such as "open now" after the cache.

What if the search index is down? Searches fail unless you have a fallback. Keep a degraded path: serve cached cells for stale results and show a notice. Business pages, backed by the database, keep working.

Index lag. If the change feed backs up, new listings or edited hours are missing from search. Alert on feed lag, and have the business page link back to the database's truth.

"Open now" across time zones. Store hours as windows in the business's local time zone and evaluate them in that zone, or a restaurant in Tokyo shows closed at noon. Daylight saving changes are a frequent source of bugs.

Fake reviews. Rate-limit review creation per user and per business, require an idempotency key so a retry cannot post twice, and hold suspicious bursts for review.

Trade-offs to name aloud

  • Search index over SQL ranges: one more system to sync, in exchange for filters and geometry in one query.
  • Eventual consistency in search: results trail a review or an edit by seconds, in exchange for a read path that never touches the primary.
  • Smoothed rating over raw average: a score the user cannot recompute by hand, in exchange for rankings that resist a few early votes.
  • Cell caches: many users share one result list, at the price of a staleness window and a small error near cell borders.

What interviewers listen for

  • A working answer: a place table, a geospatial index of some kind (geohash or quadtree), a cache, and a split between the business page and search.
  • A strong answer: explains why a bounding box with a B-tree fails, handles uneven density, keeps the search index as a derived copy fed by a change stream and states the staleness this creates.
  • A standout answer: designs the ranking with a smoothed rating and explains the caching key, treats the radius as adaptive, and raises time zones for "open now" and review abuse without being asked.

Check your understanding

Common mistakes

Treating it as only a geohash question. Geometry gets you candidates. The interview is mostly about combining it with filters and ranking, which is why a search index belongs in the answer.

Using a fixed radius or cell size. Uneven density breaks it both ways. Say that radius and cell level adapt.

Making the search index the source of truth. It is a derived, eventually consistent copy. Writes go to the database and flow outward by a change feed.

Ranking by raw average rating. A single 5-star review should not outrank 800 reviews at 4.7. Smooth the rating.

Ignoring time zones. "Open now" depends on the business's local time, and daylight saving shifts it twice a year.

Caching every filter combination. The hit rate collapses. Cache the common shape and filter the rest after it.

Practice

A holiday weekend triples search traffic, and p99 latency climbs because the search index nodes are saturated. What do you change, and in what order?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Start with what you can serve without touching the index, then add capacity, then shed what is least valuable.

Show a strong answer

Cache first. At 3× the 1,700-per-second peak, the load is about 5,000 searches a second. Cell-and-category results are shared by many users, so raise the cache TTL from seconds to a few minutes for popular cells. A listing that is two minutes stale harms nobody, and the hit rate rises sharply.

Add replicas, not shards. The index is 15 GB, so each node can hold a full copy of its shards. Adding replicas adds read throughput with no re-partitioning. Sharding more would add merge work to every query.

Cut per-query cost. Return a smaller page size, fetch fewer candidates before ranking (say 200 instead of 1,000), and push filters into the index so it prunes early.

Shed last. If it is still saturated, return the cached results for the nearest cell with a notice rather than failing, and rate-limit the clients that refresh every second.

The pattern worth keeping: when a read-heavy system saturates, exhaust cache, then replicas, then query cost, before you redesign anything.

The interviewer says owners complain that their edited opening hours take minutes to appear in search results. How do you find the cause and fix it?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

The write goes to the database first. Trace the path from the primary to the index.

Show a strong answer

Measure each hop. The edit commits to the primary, a change feed reads it, a worker transforms it and bulk-indexes it, and the index makes it searchable on its next refresh. Record the timestamp at each hop and find which one grew.

Likely causes. A backed-up change feed consumer, batches that wait too long to fill, or an index refresh interval set to many seconds for write throughput. Each has its own fix: more consumers, a shorter batch timeout, a shorter refresh interval.

Fix the product too. The owner's own page reads from the database, so it can show the new hours immediately. Show the owner a notice that search will update shortly, and alert on feed lag so you know before they do.

The pattern worth keeping: a derived index has a lag budget, so measure it per hop and alert on it, and keep a path that reads the source of truth for the person who just changed it.

Key takeaways

  • Geometry finds candidates; filters and ranking decide the answer. Pick the structure by the shape of the query.
  • A B-tree on latitude and longitude fails because proximity is two-dimensional.
  • Density is uneven, so the radius and cell level must adapt.
  • The search index is a derived copy, fed by a change stream, eventually consistent, never the source of truth.
  • Store rating_sum and rating_count, and rank with a smoothed rating.
  • Cache by cell and common filters, and apply the long tail of filters after the cache.

Further reading

  • Elasticsearch Reference (Elastic): geo-distance query and geo point field documentation.
  • Redis documentation: the GEOSEARCH command and geospatial indexes built on sorted sets.
  • S2 Geometry library documentation (Google): cell hierarchy used to index regions of the sphere.
  • H3 documentation (Uber): hexagonal hierarchical spatial index.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track