← all posts

How FriendPath Works: Bidirectional BFS Explained

FriendPath finds the shortest chain of friends connecting any two Roblox players, usually in under a minute, sometimes on networks that involve checking hundreds of thousands of accounts. The trick isn't faster hardware or a fancy database — it's a single algorithmic choice that flips the search from O(nd) to roughly O(nd/2). Here's what's actually happening under the hood.
Short answer
FriendPath uses bidirectional breadth-first search: it expands outward from BOTH usernames simultaneously and stops when the two frontiers collide. For a 6-degree path this is ≈10,000× faster than searching from one direction. The site rotates through mirrored Roblox API proxies and keeps ~250 friend-list requests in flight at once.

The data we have to work with

Roblox exposes a public friends API at https://friends.roblox.com/v1/users/{id}/friends. Given a user ID, it returns the IDs of every public friend of that user. That's it. No mutual-friend index, no precomputed graph — just a single lookup, one user at a time.

So the problem becomes: given two usernames, and the ability to query one user's friend list at a time, find the shortest chain connecting them.

The naive approach

The obvious algorithm is a breadth-first search starting from one user. You expand outward in layers:

You stop the moment you find user B. The problem: even though Roblox is "only" six degrees deep, layer 4 alone requires 6 million API calls. Each call takes a network round trip (50-200 ms). Even running 200 requests in parallel, that's 30+ minutes just for layer 4. For deeper paths, the math gets unmanageable fast.

The fix: search from both ends simultaneously

The breakthrough is almost embarrassingly simple. Instead of searching from just A, search from both A and B at the same time, alternating layers. Stop the moment the two frontiers collide — the moment the same user shows up in both searches.

Here's the difference visually. To find a 6-hop path:

The savings compound exponentially with depth. For a 4-hop path it's a ~50× speedup. For 6 hops it's more like 10,000×.

It's a similar trick to meet-in-the-middle attacks in cryptography. Two parallel searches that each cover half the depth always crush a single search that covers the full depth, because the search space is exponential in depth.

The detection step (where most implementations get it wrong)

Detecting the collision between two frontiers is subtle, and there's a great writeup by zdimension titled "Everyone gets bidirectional BFS wrong" that goes into this in painful detail. The short version:

Most implementations check "did the new user we just discovered exist in the other frontier?" That sounds right but is subtly wrong: it misses paths where two frontiers meet at the same depth through a user neither has fully expanded yet. You can end up reporting a longer path than the optimal one.

The correct approach: after expanding a layer from one side, check every node in that newly-discovered layer against the other side's visited set, not just its frontier. FriendPath tracks both visited sets in two hash maps that hold each user's parent pointer for reconstruction. When a collision is found, we walk back up both parent chains and stitch them together to produce the actual path.

The infrastructure that makes it fast in practice

Even with bidirectional BFS, a 5-hop search might need to fetch friend lists for 5,000–50,000 users. Doing that serially over Roblox's API would take hours. So:

Edge cases the algorithm has to handle

Why it scales to 70 million users

The clever thing about bidirectional BFS in a small-world network like Roblox is that it doesn't actually have to know about the 70 million users that exist. It only ever touches the small fraction that lie within (d/2) hops of either endpoint — usually a few thousand to a few hundred thousand. The graph could be a billion nodes and the algorithm wouldn't slow down, because the relevant subgraph is exactly the same size.

If you want to use it programmatically

FriendPath exposes the same search through a public API. There's a free public endpoint that returns the path as JSON, plus a metered endpoint for higher-volume use. The full reference is on the docs page.

See it run

Watch the bidirectional BFS expand in real time on the main page.

Try FriendPath now →

Quick FAQ

What is FriendPath?

FriendPath is a free web tool that finds the shortest chain of friends between any two Roblox accounts using bidirectional breadth-first search over Roblox's public friends API. Runs in your browser, no install, no Roblox login required.

What does "degrees of separation" mean on Roblox?

It's the number of friend links between two accounts. If you're friends with someone who's friends with David Baszucki, you are 2 degrees of separation from David Baszucki. Most active Roblox players are within 3–5 hops of any famous account.

Is FriendPath free?

Yes. The web tool at friendpath.arbastro.com is 100% free, ad-supported. The public API offers 50 free calls per day with paid tiers beyond. See the API docs for details.

Does FriendPath work with banned or terminated accounts?

Yes — Roblox's friends API still returns friend lists for banned/terminated accounts, so FriendPath can traverse through them. The path is computed on the public friend graph, not on a player's active session.