To estimate capacity, we can use the following assumptions:
We assume that the connections are stored as an adjacency list or graph structure in a database. Each connection consists of two user IDs, so the required storage space can be calculated as:
We need to allocate additional space for indexing, metadata, and other entities, such as user profiles. Estimating around 50% overhead, the total space required for storing connections and metadata would be approximately 4.8-5 GB.
We can break the system into the following components:
GET request to /api/connection/shortest, providing the from_user_id and to_user_id.from_user_id and to_user_id).POST request to /api/connection/add, providing the two user IDs that are forming a connection.The Graph Processor is responsible for calculating the shortest path between two users. Given that the system must scale to handle millions of users and hundreds of millions of connections, the Graph Processor must be designed to handle this efficiently.
Breadth-First Search (BFS) is ideal for finding the shortest path in an unweighted graph, such as a social network where each connection represents an equal "hop" between users.
from_user_id node.to_user_id is found.