1 · Route the search
A friend search moves from the client through the public web path to Query API.
Flow
Client → DNS and Load Balancer → Web Server → Query API.
Interactive diagram · architecture
A friend search moves from the client through the public web path to Query API.
Client → DNS and Load Balancer → Web Server → Query API.
The graph service asks Lookup Service which Person Server holds the source person.
Query API → User Graph Service → Lookup Service → Person Server.
User Graph Service runs breadth-first search and retrieves each adjacent person by ID.
User Graph Service → Lookup Service → Person Server, repeated for friend IDs.
Complete or partial BFS traversals can be stored to speed up later lookups.
User Graph Service → Memory Cache → later graph lookups.
A person’s app or browser starts a friend search.
It resolves the site name with DNS. It then sends the search request to the Load Balancer.
The public request uses a REST API.
DNS maps the site name to an address.
It receives the client lookup. The client then sends the request to the Load Balancer.
It is another service in the request path.
A load balancer distributes incoming requests.
It receives the client request. It forwards the request to a Web Server.
It adds a separate component before the web layer.
The web server runs as a reverse proxy.
It receives a request from the Load Balancer. It forwards the request to Query API.
The reverse proxy adds another hop before Query API.
The public REST API accepts a friend search.
Web Server forwards the request here. Query API sends it to User Graph Service.
External communication uses REST, while internal communication can use RPC.
This service finds the shortest path through friend relationships.
It receives the search from Query API. It uses Lookup Service, then Person Server, to retrieve people and run BFS.
Searching can take considerable time, so the design can set a time or hop limit.
A lookup maps a person ID to a Person Server.
User Graph Service asks it where a person is stored. It identifies the Person Server for the next retrieval.
The graph service may need this lookup again for every adjacent person ID.
A Person Server stores people by person ID.
Lookup Service identifies this server. It returns the person and their friend_ids to User Graph Service.
User data must be sharded because all users and relationships do not fit on one machine.
Step 4 · Reuse cached traversals
A memory cache holds person data and saved BFS traversals.
User Graph Service checks or stores complete or partial traversals here. Later searches can reuse them before more Person Server lookups.
Cached traversals need an update strategy.
Detail · follows playback, or click any box or step to pin it
Close · follow playbackClick any box for an explanation, or use Next or Play to walk through the four flows.
The client resolves DNS and sends the search through the load balancer and reverse proxy to Query API.
Query API receives the public friend-search request.
User Graph Service asks Lookup Service which Person Server contains the source person.
The Person Server returns the person and their friend_ids.
User Graph Service runs BFS from the source person through friend IDs.
Each adjacent person can require another Lookup Service and Person Server retrieval.
Complete or partial BFS traversals can be stored to speed up later searches.
Memory Cache reduces traffic to downstream services for repeated searches.