System 12.34 — Proximity Service (Nearby Places / Yelp)
In one line
Find businesses near a location, with filters and ranking. Places change rarely and reads dominate, so a geospatial index (geohash/quadtree) cached per cell serves millions of 'nearby' queries cheaply.
Think of it like this
Asking a local guide 'good cafés within walking distance?'. They don't list every café in the country; they think of your neighbourhood and the ones next to it, then recommend the best-rated ones.
Key ideas
- 01
Requirements: 200 M businesses, ~5 k search QPS (peaks higher), search radius 0.5–20 km, filters (category, open now, rating), business owners edit details (rare writes, eventual consistency of minutes is fine).
- 02
Two services: BUSINESS SERVICE (CRUD on a relational DB, replicated) and LOCATION-BASED SERVICE (read-only, stateless, horizontally scaled). The LBS answers: compute the geohash cells covering the radius (own cell + neighbours, precision chosen from the radius), fetch business IDs per cell, filter by exact distance, rank, paginate (Phase 13B, geospatial indexing).
- 03
Index storage: a table
geohash (6 chars) → business_idindexed by geohash, or Redis GEO sets, or a search engine with geo queries when combined with text search and filters. The whole geo index for 200 M places fits in memory on a few nodes (~a few GB), so replicate it rather than shard it. - 04
Caching: results per (cell, category) in Redis with a TTL, because nearby queries in dense areas are highly repetitive. Business edits publish events that update the index asynchronously.
Code & diagrams
Explain without notes
Why replicate the geo index instead of sharding it?
Practice
Users complain dense city searches are slow. What do you change?
Trade-offs
- ↔
Geohash tables are simple and cacheable; quadtrees adapt to density but live in memory and must be rebuilt/updated.
Run it in production
You've designed it. Now build, operate, and break the same idea hands-on in the DevOps courses:
Completion checklist
I can size the index and explain why reads are served from replicated, cached geo cells