Design a Nearby Places and Friends
Design a location service with two features. Nearby places: a user opens the app, and it lists restaurants, shops and other places within a radius they choose, filtered by category and sorted by distance or rating, with a details page for each place. Nearby friends: users who opt in see which of their friends are close by right now, with the distance updating as people move.
There are 200 million places and 100 million daily users. Search is read-heavy and the place data barely changes, so the hard part is answering “what is within 2 km of this point?” in under 100 ms without scanning a table. Nearby friends is the opposite: at peak 10 million phones each send a new location every 30 seconds, about 334,000 writes a second of data that is stale within minutes, and each update has to reach every online friend within a few seconds.
Good questions to ask first
Decide what you would assume for each before you look at ours.
- 1How many places and users?
- 2What radius can a user search?
- 3How fresh must place data be?
- 4Is nearby friends opt-in?
- 5How close counts as nearby for friends?
- 6How often does a phone send its location?
- 7How many friends does a user have?
- 8Do we keep location history?
How to spend the 45 minutes
- 5minPart 1: Requirements: two features, two load shapes
- 5minPart 2: Estimates
- 5minPart 3: API, including the WebSocket
- 15minPart 4: Architecture, stage by stage
- 15minPart 5: Geohash, pub/sub scaling, privacy