Skip to content

How to design Yelp

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A proximity service answers one question: which businesses sit within a chosen distance of where someone is standing, and then opens the page of the one they tap. The data changes slowly while reads keep coming: roughly 5,000 searches a second, with 200 million businesses to search through. The answer turns on converting a two-dimensional "near me" question into a key lookup: give each business a compact key naming the map cell it sits in, read that cell together with the ring of cells around it, and check the true distance on the candidates that come back. The whole index comes to about 1.7 GB, which settles how to store it: copy it to replicas rather than split it, and let the search rate, not the size, decide how much to cache.

Clarifying questions

AskWhy it mattersA typical answer

How many businesses are there, and how many searches a day do people run?

The business count sizes the index, and the search rate sizes the read path. Together they tell you whether one machine can hold the index and whether the database can be on the search path at all.

About 200 million businesses and 100 million daily users, each searching about 5 times a day: about 5,000 searches a second. A smaller framing of the same question assumes 10 million businesses, which changes little about the shape of the design.

Can the user choose the radius, and is there a maximum?

A fixed set of radii lets you precompute one cell size per radius and cache by it. An arbitrary radius forces you to cover the circle with cells at query time.

A fixed set: 0.5, 1, 2, 5 or 20 km. Start with the user's choice and widen it when a search comes back nearly empty.

How quickly must an owner's edit show up in search?

Freshness decides how long you may cache, and whether the index needs updating on each edit or in a batch.

Edits can appear the following day. That allows a daily cache lifetime and a nightly batch, which is far simpler than live index updates.

Is the user standing still while they search, or moving?

A moving user turns this into a live location problem, where the client re-queries and the server may stream. A stationary user makes each search independent, so the cache can be keyed by place.

Assume the user is stationary for a search. Moving objects, like drivers, are a different question.

Do results need ranking or filters, such as category or open now?

Filters decide where the result set is narrowed: inside the index, in a search engine, or in memory after the cells are read. Ranking beyond distance brings in ratings and relevance, which is a different system.

Order by distance for now. Be ready for a follow-up about filtering by type or opening hours, and have a place for it in the design.

Where do our users live, and are there rules on where their location data may go?

Location is personal data. If some countries require it to stay local, the deployment needs a region there and routing that keeps requests inside it.

Users search from many countries. Treat location as private data and be ready to deploy in more than one region.

Is the result a list or a map, and does it page?

A map view needs bounding-box queries and tile rendering; a paged list needs a stable order and a cursor. They lead to different APIs.

A paginated list sorted by distance. Viewing results on a map is out of scope.

The requirements menu

RequirementScopeWhy

Find businesses within a chosen radius of the user: 0.5, 1, 2, 5 or 20 km

Core

The product. The fixed radii matter: each one maps to a geohash precision (some radii share one), so the index and the cache can be built per radius ahead of time.

View a business’s details

Core

The other read path, and the second cache: business pages are read far more often than they change.

Business owners add, update and remove a business; changes show the next day

Core

The write path, and the freshness rule that permits a day-long cache and a nightly refresh instead of live index updates.

Widen the radius when a search returns too little

Optional

Worth taking: a sparse area at the smallest distance returns nothing, and the fix is cheap, since a shorter cell code covers a bigger area. Say how you widen and what it costs in candidates to filter.

Filter results by category or by open now

Optional

Take it if asked: it is the usual follow-up. The geographic candidate set is small, so filters can run in memory after the cells are read, which keeps the index simple.

Page through the result list

Optional

The search API already returns pages. Take it, and say that the page is cut after the distance sort, with a cursor of distance plus business id so ties don't reorder across pages, as long as the list doesn't change underneath.

Sort results by distance

Optional

Nearly free once you compute the real distance to filter false positives from the cells, so take it. Ranking by rating or relevance is a different system, so leave that out.

Reviews and ratings on the business page

Out of scope

Reviews bring user-generated writes and moderation, a different shape of work from the search path, which takes no writes. Name it, keep a place for a rating field on the business, and move on.

Search businesses by name or text

Out of scope

Text search wants an inverted index or a search engine. It changes the storage choice, so agree with the interviewer to leave it out unless they want it.

Viewing results on a map

Out of scope

A map needs bounding-box queries and map tiles, which is a different query shape from a radius. Leave it out.

Personalised recommendations

Out of scope

Recommendations usually bring in user history or a ranking model. The proximity search stays the same underneath, so leave them out.

Real-time business updates

Out of scope

Next-day freshness is agreed, so edits can be batched. Live updates would mean propagating each edit promptly to the index and the caches, by invalidation or change capture, which is more machinery than the next-day rule needs.

Non-functional requirements

RequirementWhat it forces

About 5,000 searches a second

The search path must be stateless and horizontally scaled, and it should avoid a database query per search where it can: each search becomes a few key lookups against a cache of cell contents, with the database behind it serving misses from replicas. An indexed query against read replicas is a defensible first version; the cache is what you add when the replicas run hot.

Low latency search (Hello Interview: under 500 ms)

A search does a handful of memory lookups in parallel, then a distance filter over the candidates from nine cells, a small set next to the table even where a dense downtown returns thousands. No scan, no join, and the business details come from a cache too.

Highly available; eventual consistency is fine

No single machine on the read path: several service instances, a cache cluster, and read replicas of a small index. Edits reach the index and the caches later, within a day, so the read side keeps answering while the write side is down.

Location data is private and handled within the law

Don't log raw coordinates or key a cache by them, keep what you store coarse, and be able to run a region inside a country whose law requires its users' data to stay there, with routing that keeps those requests inside it.

Estimates

QuantityWorkingResultWhat it sizes

Search rate

100 million daily users × 5 searches = 500 million searches a day; ÷ 100,000 seconds ≈ 5,000 a second (÷ 86,400 seconds ≈ 5,800)

About 5,000 searches a second, a little more with a true day; assume the peak is some multiple of that

The read path: how many service instances and cache lookups the design must carry.

Row reads if each search scanned the business table

200 million rows × 5,000 searches a second = 10^12 row reads a second

A trillion row reads a second

Why a geospatial index is not optional: a scan path on a single relational server is nowhere near that workload, so each search must touch a few cells, not the whole table.

Geohash length for each radius

Wikipedia's geohash table gives the error of a cell by code length: length 4 about ±20 km, length 5 about ±2.4 km, length 6 about ±0.61 km. Choose the shortest length whose cell plus its neighbors covers the radius: 0.5 km → length 6; 1 km and 2 km → length 5; 5 km and 20 km → length 4

Three cell sizes, lengths 4 to 6, cover all five radii

How many precisions to index and cache: three lists of ids per business, one per length.

Geo index size

Alex Xu's notes put the quadtree index at about 1.71 GB and call a geohash index similar in size. Cross-check: 200 million × 8-byte business id = 1.6 GB of ids by themselves, so the figure is mostly ids; a six-character code per row would add about 1.2 GB to a plain table, so treat 1.7 GB as the floor and a few GB as the ceiling. Either fits in one server's memory

About 1.7 GB for the whole index at one precision

Whether one server holds the index in memory: it does, so copy it to replicas rather than split it.

Redis memory for cell lists at three precisions

8-byte id × 200 million businesses × 3 precisions = 4.8 GB ≈ 5 GB

About 5 GB of values per copy of the cache

One Redis cluster per region can hold a full copy, so each region serves cell lookups locally.

Cache lookups a second

5,000 searches a second × 9 cells per search = 45,000 cell lookups a second

About 45,000 small reads a second across the cache

The cache read load, spread over cache nodes and regions; the nine lookups per search run in parallel so latency stays at one round trip.

Quadtree leaves

200 million businesses ÷ 100 businesses per leaf = 2 million leaves

About 2 million leaf nodes

The memory of an in-memory quadtree, and why building it at startup takes minutes, which decides how you roll out new servers.

Business table size

200 million businesses × about 1 KB of details each (an assumption) = 200 GB

About 200 GB

Whether the business table needs sharding: a single primary with replicas carries it, so sharding waits until the table outgrows one server.

Core entities

EntityWhat it holds

Business

One row per place: where it is, what it is called, and the details shown on its page. Owned by the business service and written by owners.

Geo index row

The map cell a business sits in. One row per business at the finest precision; a coarser cell is a prefix range on the same key, so a cell's contents are a range read.

Cached cell list

A Redis entry per cell at each cached precision: the ids of the businesses inside it, kept for a day.

The API

EndpointNotes

GET /v1/search/nearby?latitude&longitude&radius → { total, businesses } paginated

A read, served by the location service. The radius is one of the five allowed values and picks the cell size. Results come back sorted by distance with a page cursor. Don't log the coordinates at full precision.

GET /v1/businesses/{id}

Served by the business service from a Redis cache of business details, with the database behind it on a miss. Business data changes rarely next to how often it is read, which is why this call is cached too.

POST /v1/businesses

Restricted to the owner. Writes the row to the primary and computes the geohash for the index row in the same transaction. The new business appears in search after the nightly refresh, which is the agreed freshness.

PUT /v1/businesses/{id}

Restricted to the owner. If the location changed, the index row moves: delete the old (geohash, id) pair and insert the new one. Cached cell lists keep the old picture until their day is up or the nightly job replaces them.

DELETE /v1/businesses/{id}

Restricted to the owner. Removes the row and its index rows. A cached cell list may still name the id for up to a day; the hydration step treats a missing business as gone and drops it from the results rather than failing the search.

The high-level design

searchbusinesswriteprefix queryClientLoad balancerLocation serviceBusiness serviceMySQL primary

Step 1 of 4

Two services and one database

Split the traffic by what it does. A location service answers searches and does nothing else: it takes no writes and keeps no state, so you add instances for lunchtime and remove them at night. A business service handles the page view and the owner's add, update and delete. Both sit behind a load balancer and share one MySQL primary holding the business table and a geohash index table, where each row is a business id with the code of its map cell. The search reads the index with a prefix match on that code rather than scanning the table.

searchbusinessnine cellshydratemissmisswritereplicateeditsrefreshrefreshClientLoad balancerLocation serviceBusiness serviceRedis: cell to idsRedis: businessesRead replicasMySQL primaryNightly job
The whole design

What breaks first

The deep dives

Indexing locations. A user wants the businesses within 2 km of a point, out of 200 million. How do you find them without reading the table, and does that index live on one machine or many?

A concept that helps here: Geospatial indexingA concept that helps here: Database indexesA concept that helps here: Replication and read replicas

Edges, neighbours and the radius. A user stands a step away from a cell boundary and searches within 500 m. Walk the request from the point to the sorted results, and say which businesses a naive lookup would miss.

A concept that helps here: Geospatial indexingA concept that helps here: Walking one request through the designA concept that helps here: Caching strategies

Caching and regions. Lunchtime traffic concentrates on a few big cities, and users search from many countries. What do you cache, under which key and for how long, and where does the service run?

A concept that helps here: Caching strategiesA concept that helps here: Cache invalidation and TTLsA concept that helps here: Running in several regions

Concepts this guide uses

Sources

  1. Alex Xu, System Design Interview volume 2, chapter 17: Proximity Service (notes at books.dwf.dev)
  2. System design notes: Proximity Service chapter
  3. htadev: Design a Proximity Service System
  4. Copilot Interview: Design a Proximity Service (Yelp / Nearby Places) walkthrough
  5. Wikipedia: Geohash
  6. Wikipedia: Quadtree
  7. Redis documentation: GEOSEARCH
  8. Redis documentation: Geospatial data type
  9. Redis documentation: EXPIRE
  10. OneUptime: How Redis geospatial indexes work internally
  11. System Design School: Design Yelp
Sign in to report a mistake