KatInterview

Nearby Places Lookup: Architecting a Proximity Search Backend

System DesignModel answer
MediumModel answerSystem Designsystem-designgeospatialgeohash

Last updated

Design a read-heavy backend that returns places within a given radius of a coordinate, covering spatial indexing, caching, API shape, capacity math, and availability.

Nearby Places Lookup

You are asked to design the backend for a "what's near me?" feature. A client sends its current latitude and longitude, and the service returns the places (points of interest, or POIs) that lie within a chosen distance of that spot.

Functional requirements

  • Accept a coordinate pair and a search radius (for example 5 km) and return all matching places.
  • Each result includes the place name and its exact coordinates.

Non-functional requirements

  • Search latency under 100 ms.
  • High availability.
  • The place catalog changes rarely, so the workload is overwhelmingly reads.

Scale assumptions

  • 10 million places worldwide.
  • 1 million daily active users.
  • Read-to-write ratio of about 1000:1.

What your answer should cover

  1. Data model: how coordinates are stored and which indexing strategy makes radius queries fast.
  2. API design: the endpoint and response shape for a proximity search.
  3. Architecture: the main components (load balancer, application servers, cache, datastore) and how reads and writes flow through them.
  4. Trade-offs: compare candidate approaches such as geohash, quadtree, and a spatial database extension like PostGIS, and justify your pick.

Back up your design with rough capacity numbers, and say what you would do differently if the scale grew by 10x or 100x.

Hints

Hint 1

Do the sizing before choosing a design: estimate the memory needed for an index of 10M (id, lat, lng) entries and the peak queries per second. Does the data need partitioning, or only replication?

Hint 2

A plain B-tree on latitude and another on longitude cannot answer a 2D box query efficiently. Think about what property a spatial index must preserve, and how a geohash or a tree-based structure turns 2D proximity into something cheap to look up.

Hint 3

A cell-based lookup returns candidates, not final answers. Remember to check neighboring cells (points near a cell edge can be close but have a different prefix) and to apply an exact distance filter at the end. Then think about dense versus sparse regions.