Skip to content

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

Capacity Estimation


High-Level Architecture

High-Level Architecture


Geospatial Indexing

Approach 1: Geohash

Geohash

Approach 2: QuadTree

QuadTree

Approach 3: PostGIS / Spatial Database

PostGIS (Spatial Database)


Search Flow

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

Caching Strategy


Read/Write Paths

Read/Write Paths


Interview Discussion Points

  1. How do you index 200M businesses for geo search?
  2. Geohash for simple queries
  3. Redis GEORADIUS for in-memory speed
  4. PostGIS for complex spatial queries

  5. How do you combine location + text search?

  6. Two-phase: geo filter → text filter
  7. Or Elasticsearch with geo queries

  8. How do you rank search results?

  9. Distance, rating, review count
  10. Relevance to search terms
  11. Paid placement for businesses

  12. How do you handle updates?

  13. Write to primary DB
  14. Async update search indexes
  15. Invalidate caches

  16. How do you scale read traffic?

  17. Geospatial index in memory (Redis)
  18. Read replicas for DB
  19. Aggressive caching

  20. How do you handle user location changes?

  21. Client-side debounce
  22. Search result caching by geohash
  23. Smooth transitions in UI