CSE Roadmap

Common tier · about 4 hours · 7 parts

Part 3 of 7 · 1 min read

Compare

Static versus moving data.

Nearby places (Level 11) stores shops that do not move. A search asks "what is within 2 km of this point?", and a geohash or quadtree answers. Writes are rare and reads are many.

Nearby friends flips this. Every user moves. Writes are constant (334,000 a second), and the question is not "who is near this point?" but "which of my friends are near me, right now, and tell me when that changes?" The set of friends is small and known, so there is no need to search a map. The need is fast delivery of each change to the friends who care.

Nearby places Nearby friends
Data Static shops Moving people
Writes Rare 334,000 a second
Query Search by area Fixed set of friends
Key problem Index by space Push updates quickly
Store Geo index, replicas In-memory cache, pub/sub

A worked example (made up). User A has 3 online friends in her list: B 2 miles away, C 4 miles away, D 30 miles away. When A moves, B and C must see it, and D need not. The system sends A's update to all three handlers, and each checks the distance. The one for D drops it.

Common mistake

Reusing a geohash search for this feature. The friend list is small, so a distance check per friend is cheaper than a spatial index over everybody.

Check yourself: 1. What stays fixed in nearby friends, and what moves? 2. Which case has constant writes? 3. Why drop D's update?