System DesignAdvancedarticle

System Design: Designing a Proximity Service (Yelp/Google Maps)

Learn how to design a proximity service like Yelp or Google Maps. A technical deep dive into Geohashing, proximity searches, and how to scale location-based queries.

Sachin SarawgiApril 20, 20263 min read3 minute lesson

System Design: Designing a Proximity Service (Yelp)

A Proximity Service allows users to find nearby places (restaurants, gas stations, etc.). The technical challenge is searching millions of businesses based on a user's current GPS coordinates with millisecond latency.

1. Core Requirements

  • Add/Update Business: Business owners can add or modify their listings.
  • Proximity Search: Users find businesses within a given radius (e.g., 5km).
  • Filtering: Filtering by category, rating, or price.

2. The Scaling Problem

Storing latitude and longitude in a standard database index (B-Tree) is not enough. A standard index only works on one dimension. To find businesses near a point, we need a 2D Spatial Index.

3. The Solution: Geohashing

Geohash is a popular technique that divides the world into a grid and assigns each cell a short string of letters and numbers.

  • The Logic:
    1. The world is divided into 32 large squares.
    2. Each square is subdivided recursively.
    3. The more characters in a Geohash string, the smaller and more precise the area.
  • Example: 9q8yy is a broad area in San Francisco, while 9q8yyzh is a specific street corner.

Geohashes have a unique property: Prefix Matching. Two locations that are close to each other will often share the same Geohash prefix. To find restaurants near a user, we simply calculate the user's Geohash and perform a Prefix Search in our database.

4. Database Selection

  • Metadata Store: PostgreSQL or MySQL to store business details (name, description, menu).
  • Index Store: Redis or Elasticsearch is ideal for Geohash indexing.
    • Redis Geospatial (GEOADD/GEORADIUS): Uses Geohashes internally to provide (\log N)$ proximity searches.

5. Handling High Read Volume

Proximity services are read-heavy.

  • Caching: Cache the results of popular searches (e.g., "Sushi in Manhattan") in Redis.
  • Read Replicas: Since data updates (new restaurants) are rare, we can scale out using read replicas across different geographic regions.

6. Edge Case: The "Boundary" Problem

If a user is at the very edge of a Geohash cell, the nearest restaurant might be in the neighboring cell.

  • The Fix: Always search the user's current Geohash cell plus the 8 surrounding cells. This ensures no nearby locations are missed.

Summary

The heart of Yelp's architecture is Geohashing. By converting 2D coordinates into 1D strings, we can leverage traditional database indexing to build a blazing-fast proximity search engine that scales to millions of businesses and users.

📚

Recommended Resources

Designing Data-Intensive ApplicationsBest Seller

The definitive guide to building scalable, reliable distributed systems by Martin Kleppmann.

View on Amazon
Kafka: The Definitive GuideEditor's Pick

Real-time data and stream processing by Confluent engineers.

View on Amazon
Apache Kafka Series on Udemy

Hands-on Kafka course covering producers, consumers, Kafka Streams, and Connect.

View Course

Practical engineering notes

Get the next backend guide in your inbox

One useful note when a new deep dive is published: system design tradeoffs, Java production lessons, Kafka debugging, database patterns, and AI infrastructure.

No spam. Just practical notes you can use at work.

Sachin Sarawgi

Written by

Sachin Sarawgi

Engineering Manager and backend engineer with 10+ years building distributed systems across fintech, enterprise SaaS, and startups. CodeSprintPro is where I write practical guides on system design, Java, Kafka, databases, AI infrastructure, and production reliability.

Keep Learning

Move through the archive without losing the thread.

Related Articles

More deep dives chosen from shared tags, category overlap, and reading difficulty.

More in System Design

Category-based suggestions if you want to stay in the same domain.