Back to explorer
System Architectures 5 Min

Yelp

MEDIUM

Design Yelp (Proximity Search Service)

Yelp is a proximity search platform that allows users to search for local businesses, restaurants, and services in real time based on geographic coordinates.


1. High-Level Design

To perform spatial proximity queries efficiently (e.g., "Find all restaurants within 2 miles of my location"), standard SQL indexing on latitude and longitude is insufficient because databases must perform full table scans to evaluate 2D bounding boxes. Instead, we divide the earth's surface using a Geohashing grid:

code
+-------------+-------------+
|             |             |
|   gbsuv1    |   gbsuv2    |
|             |             |
+-------------+-------------+
|             |             |
|   gbsuv0    |   gbsuv3    | (User location matches gbsuv3)
|             |             |
+-------------+-------------+

Components

1. API Gateway: Entry point for query dispatching and rate limiting.

2. Business Service: Manages CRUD operations for business profiles. Writes metadata to a sharded PostgreSQL database.

3. Proximity Search Service: Handles search requests. Resolves the client's latitude/longitude to a geohash string prefix (e.g., gbsuv3) and queries a Redis cache.

4. Geo-Index Sharding: Uses Redis Geohash clusters or Elasticsearch spatial indices to lookup matching locations within the matched quadrant.


2. Potential Deep Dives

  • How would you calculate and update average rating for businesses?

We avoid synchronous database updates on review submissions. review writes stream into a Kafka Topic. A stream processor (Apache Flink) calculates running aggregates in a 1-minute window and flushes calculated updates to the primary PostgreSQL business metadata table.

  • How can you ensure that a user can only leave one review per business?

Enforce a unique composite index constraint UNIQUE(user_id, business_id) in the review database schema.


3. References & Tech Blogs