Design Yelp / Nearby Friends
Geospatial search at p95 < 200 ms: S2/H3 indexing, multi-attribute ranking, and a streaming friend-proximity service.
Intro
Yelp-style nearby search is two related problems: (1) geo-indexed point-of-interest search with category + rating filters, and (2) a friend-proximity service that streams location updates and notifies when friends are nearby. Both lean on a hierarchical geospatial index (Google's S2 or Uber's H3); the streaming surface adds a pub/sub layer with privacy-aware visibility.
Functional
- GET /places/nearby — search businesses by lat/lng + radius + category.
- GET /place/{id} — details, reviews, photos.
- POST /reviews — write a review.
- Friend proximity: notify when a friend is within R meters.
Non-functional
- Search p95 < 200 ms across 10 M businesses.
- 100 M MAU; ~50 k search QPS at peak.
- Friend updates: 1 Hz × 2 M concurrent users ≈ 2 M QPS.
Components
Geo index
S2/H3 cells, sharded by region.
Search service
Filters + ranking on category, distance, rating.
Place store
Postgres / Cassandra for businesses + reviews.
Friend service
Subscriptions + proximity notifier.
Push gateway
Notify clients on friend proximity.
Trade-offs
S2 vs H3 vs geohash
Pros
- S2: standard, hierarchical.
- H3: hexagonal, uniform neighbour distances.
Cons
- Geohash: edge-of-prefix discontinuities.
Push-on-update vs pull-on-query for proximity
Pros
- Push: immediate notify.
- Pull: no consumer load.
Cons
- Push: amplifies updates; pull: stale.
Scale concerns
- Hot cells (Times Square at 8 PM).
- Privacy-aware visibility (mutual follow + opt-in).
- Battery: client must batch + back off when stationary.