Yelp Nearby Search (Location-Based Service)¶
Quick Reference Guide for System Design Interviews
Problem Statement¶
Design a location-based service like Yelp that allows users to search for nearby businesses (restaurants, shops, etc.), view details, and read/write reviews.
Requirements¶
Functional Requirements¶
- Search businesses by location and category
- View business details and reviews
- Add/edit business listings
- Write and read reviews
- Search with filters (rating, price, hours)
Non-Functional Requirements¶
- Latency: < 200ms for search
- Availability: 99.99%
- Scale: 500M users, 200M businesses
- Accuracy: Results within specified radius
Back of Envelope Estimation¶
High-Level Architecture¶
Geospatial Indexing¶
Approach 1: Geohash¶
Approach 2: QuadTree¶
Approach 3: PostGIS / Spatial Database¶
Search Flow¶
Data Models¶
-- Businesses
CREATE TABLE businesses (
business_id UUID PRIMARY KEY,
name VARCHAR(255) NOT NULL,
address TEXT,
city VARCHAR(100),
state VARCHAR(50),
zip_code VARCHAR(20),
country VARCHAR(50),
latitude DECIMAL(10, 7),
longitude DECIMAL(10, 7),
geohash VARCHAR(12), -- For index
category VARCHAR(100),
price_range INT, -- 1-4 ($-$$$$)
rating DECIMAL(2, 1),
review_count INT DEFAULT 0,
is_open BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP,
updated_at TIMESTAMP,
INDEX idx_geohash (geohash),
INDEX idx_category (category),
INDEX idx_rating (rating)
);
-- Business hours
CREATE TABLE business_hours (
business_id UUID REFERENCES businesses(business_id),
day_of_week INT, -- 0-6
open_time TIME,
close_time TIME,
PRIMARY KEY (business_id, day_of_week)
);
-- Reviews
CREATE TABLE reviews (
review_id UUID PRIMARY KEY,
business_id UUID REFERENCES businesses(business_id),
user_id UUID NOT NULL,
rating INT CHECK (rating BETWEEN 1 AND 5),
content TEXT,
photos TEXT[],
useful_count INT DEFAULT 0,
created_at TIMESTAMP,
INDEX idx_business (business_id, created_at DESC),
INDEX idx_user (user_id)
);
Caching Strategy¶
Read/Write Paths¶
Interview Discussion Points¶
- How do you index 200M businesses for geo search?
- Geohash for simple queries
- Redis GEORADIUS for in-memory speed
-
PostGIS for complex spatial queries
-
How do you combine location + text search?
- Two-phase: geo filter → text filter
-
Or Elasticsearch with geo queries
-
How do you rank search results?
- Distance, rating, review count
- Relevance to search terms
-
Paid placement for businesses
-
How do you handle updates?
- Write to primary DB
- Async update search indexes
-
Invalidate caches
-
How do you scale read traffic?
- Geospatial index in memory (Redis)
- Read replicas for DB
-
Aggressive caching
-
How do you handle user location changes?
- Client-side debounce
- Search result caching by geohash
- Smooth transitions in UI