Question presented to candidate:
"We want a 'Nearby Friends' feature: if you opt in, you see which of your friends are within about 5 km, with the distance, and the list updates live while the app is open. Walk me through how location updates get from one phone to the right friends, and how you keep it fast and private at a hundred million daily users."
What a strong answer should cover:
The difference from a driver search: the audience is your friends, not everyone nearby, so the core is fan-out over the social graph, not a geo index
Clients hold a WebSocket; each update is written to a location cache with a TTL and published to the user's pub/sub channel; WebSocket servers subscribe to the channels of each connected user's friends
Distance filtering at the receiving side (most deliveries are dropped: 3.9% passed in the example), and why that is cheaper than indexing
Capacity: about 333,000 updates/s and 13 million pub/sub deliveries/s under the stated assumptions; sharding pub/sub channels across many nodes
Privacy and lifecycle: explicit opt-in, both sides must share, coarse distance, location history kept separately or not at all, TTL so a closed app disappears
The optional "nearby strangers" extension, which does need a geo index
Clarifying questions expected:
How many daily users, how many friends on average, and how often does a moving phone report?
Do we show exact positions or only "1.2 km away"? Do we keep location history?
Must both friends opt in, and should the list be live or refreshed on open?
Code / implementation expected: Optional β the design with numbers; the example simulates per-user channels, fan-out and the receiver-side filter.
system-design
case-study
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Developers preparing for system design interviews. You know what a cache and a WebSocket are; the geo indexing side is covered on the sibling page about nearby drivers.
Difficulty: Hard
Verified with: Node 22.22 and Python 3.12 (both print identical output).
How to read this doc: Every idea is explained in plain language first, then tagged with π Interview term: so you also learn the exact words an interviewer expects. All behaviour shown comes from running the example; the Verified section quotes the full output. Capacity numbers are worked from stated assumptions.
1. Why This Even Matters β A Story First
Imagine a group chat where every friend who has the app open posts "I am at the corner of 5th and Main" every 30 seconds. Your phone reads every message and quietly shows only the friends who are within 5 km. Nobody needs a map of the who
The solution is hidden so you can try first
14 min read Β· 16 sections
4
Read the code
Nearby Friends fan-out: per-user pub/sub channels, receiver-side distance filter, and a TTL location cache