← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 046 · Databases and storage

Design a Nearby Places Service

Medium 45 min

A maps app lets people search for places near them: 'coffee within 1 km', 'open restaurants near me'. There are 100 million places worldwide, and owners add or edit about 50,000 places a day. At lunchtime peak the app serves 30,000 nearby searches per second, each with a location, a radius between 500 m and 20 km, and optional filters such as category, rating and opening hours. Results must appear in under 200 ms, sorted by a mix of distance and rating. A newly added place may take a few minutes to appear in searches.

Functional requirements

  • Return places within a given radius of a latitude and longitude
  • Filter by category, minimum rating and 'open now'
  • Sort results by distance, rating or relevance, with pagination
  • Show a place's details page with photos and reviews
  • Let owners add and edit places

Non-functional requirements

  • Nearby searches return in under 200 ms at p95
  • Search stays available during regional failures; slightly stale results are acceptable
  • Edits appear in search results within 5 minutes

Constraints and scale

  • 100 million places, about 1 KB of searchable data each
  • 30,000 nearby searches per second at peak
  • 50,000 place edits per day (read to write ratio well above 1,000:1)

You will practise

  • Index two-dimensional locations with geohashes, quadtrees or a geospatial index
  • Handle cell boundaries and dense versus sparse areas correctly
  • Separate a read-optimised search index from the system of record
Show 3 hints
  1. A geohash prefix gives you a grid cell. Which neighbouring cells must you also check, and why?
  2. Central London and rural Scotland have very different place densities. Should every cell be the same size?
  3. Writes are rare. Could the index be rebuilt or updated asynchronously?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • A stadium crowd searches at onceAs a cup final ends, 60,000 fans in one square kilometre all search for 'bars near me'. One index shard and one cache key take almost all of the traffic.

Run them from the workspace once your design is in place.