Design Yelp / Nearby Friends - System Design
“Nearby Friends” looks like the Uber problem wearing a different hat - a map, some dots, find the ones near me. It is not. Uber asks “out of 5 million strangers moving around, who is the single nearest one,” and answers it with a spatial nearest-neighbour index. Nearby Friends asks a different and in some ways nastier question: “out of my friends specifically, which ones are within 5km of me right now, and keep that answer live as both of us walk around.” The set you care about is not “everyone near this point” - it is the intersection of two things that both change every few seconds: the social graph (who is my friend, who opted in) and live geography (who is physically close). The hard part is the fan-out: when I move, which friends need to be told, and when a friend moves, do I need to know? Do that naively for 50M concurrently-moving people each with hundreds of friends and you generate billions of pointless distance checks a second. ...