πŸŽ‰ 75% of content is free forever β€” Unlock Premium from $10/mo β†’
CW
NEWSLIVESearch All Content
πŸ’Ό Servicesℹ️ Aboutβœ‰οΈ ContactView Pricing Plansfrom $10

Design a Proximity Service

System Design ProblemsLocation-Based Search🟒 Free Lesson

System Design Problems

Design a Proximity Service

A proximity service finds nearby points of interest (restaurants, gas stations, ATMs) based on a user's geographic location. The system must efficiently query millions of locations within a given radius using geospatial data structures.

  • Nearby Search β€” Find all businesses within a radius
  • Geospatial Indexing β€” Efficient range queries on lat/lng coordinates
  • Real-time Updates β€” Business locations change; index must stay current

The core challenge is efficiently querying a 2D space. A naive approach checks every location (O(N)), but geospatial indexes reduce this to O(log N) or O(1) for bounded regions.

Requirements

Functional Requirements

  • Search for businesses near a location (lat, lng, radius)
  • Return results sorted by distance
  • Business details (name, address, hours, rating)
  • Search by category (restaurants, cafes, etc.)
  • Add/update/remove business locations
  • Filter by open hours, rating, price range

Non-Functional Requirements

  • Latency: Search results in < 200ms
  • Scale: 100M businesses, 10K QPS
  • Accuracy: Results must be within specified radius
  • Freshness: Location updates reflected within 1 minute
  • Availability: 99.99%

Back-of-the-Envelope Estimation

Geospatial Indexing

Geohashing

9q8yy9q8yz9q8y09q8y19q8yk9q8ym9q8yn9q8ypSearch RadiusGeohash grid with search radius (dashed circle)

Query Algorithm

High-Level Architecture

ClientCDNProximity ServiceGeohash EncoderNeighbor FinderDistance CalculatorResult RankerCache ManagerRedisGeohash IndexPostgreSQL+ PostGISElasticsearchgeo_pointProximity Service Architecture

Database Schema

CREATE TABLE businesses (
    id          UUID PRIMARY KEY,
    name        VARCHAR(200),
    address     TEXT,
    latitude    DECIMAL(10, 8),
    longitude   DECIMAL(11, 8),
    geohash     VARCHAR(12),
    category    VARCHAR(50),
    rating      DECIMAL(2, 1),
    open_hours  JSONB,
    created_at  TIMESTAMP
);

CREATE INDEX idx_geohash ON businesses(geohash);
CREATE INDEX idx_category ON businesses(category);

Caching Strategy

Cache popular geohash cells:

  • Cache key: geo:{geohash_6}:{category}
  • Cache value: List of business IDs sorted by rating
  • TTL: 5 minutes (balance freshness vs. performance)
  • Cache hit ratio target: > 80% for popular areas

Practice Exercises

  1. Algorithm: Implement geohash encoding from latitude/longitude. What is the precision at 6 characters?

  2. Scale: If 100M businesses are distributed globally, estimate the Redis memory needed for geohash indexes at 6-character precision.

  3. Optimization: How would you handle a search in a sparse area (no businesses within 5 km)? Design a strategy to expand the search radius dynamically.

  4. Real-time: How would you update the geohash index when a business moves to a new location? Design an atomic update strategy.


What to Learn Next

-> Design Google Maps Routing, traffic, and map tile infrastructure.

-> Database Indexing B-tree, GiST, and geospatial index structures.

-> Caching Strategies Caching geohash cells and popular search results.

-> Design Search Autocomplete Location-based typeahead suggestions.

-> Databases PostGIS and geospatial database support.

-> Consistent Hashing Geohash-based data distribution.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-09-15

β€”
β˜†β˜†β˜†β˜†β˜†
0 ratings

Rate & Feedback

Need Expert System Design Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement