Medium · 11 steps · ~60 min
Design a proximity service (nearby search)
Turn latitude and longitude into fast 'near me' lookups for millions of people.
A local-search app shows the places near you: cafes, shops and services. Searches vastly outnumber changes to the places themselves, and the queries are geographic, which ordinary indexes handle poorly.
Same problem as YelpGoogle Maps nearbySnap Map
How it works
- Search: given a position and radius, return nearby places.
- Details: open one place.
- Update: owners add or move places; users may also share live positions.
What you'll build
- The API and a geohash-based data model
- Caching and a CDN keyed by map cell
- A geo index and a write-behind cache for location updates
- Sharding by region
- A design that survives a cold cache and a lost index node
Steps
- 1Design the API
- 2Design the data model
- 3Serve 2,000 requests per second
- 4Cache hot areas at 20,000 requests per second
- 5Add a geo index and a CDN at 60,000 requests per second
- 6Absorb location updates at 50,000 requests per second
- 7Geohash or quadtree?
- 8Go worldwide at 300,000 requests per second
- 9Choosing the shard key
- 10Survive a cold cache at 16,000 requests per second
- 11Lose a geo index node