Free sample lesson · Netflix Real-Time Distributed Graph: Query Engine Design
Why BFS beats DFS for distributed graphs
Lesson 1 of the Wondering course Netflix Real-Time Distributed Graph: Query Engine Design
The distributed graph problem
Graph data does not always live on one machine. Nodes and their neighbors can sit behind network calls.
Every hop you traverse may cost a round-trip over the network.

Notice that every edge the traversal follows must cross the network boundary, so each hop costs a round-trip.
So the traversal order you choose is not just a style choice. It decides how many times you pay that network cost.
How BFS batches by depth
Breadth-first traversal walks the graph one depth level at a time.
All nodes sitting at the same depth get grouped into a single parallel batch. You fetch that whole level together, then move to the next.
- Take current level: Collect every node sitting at the same depth.
- Group into batch: All nodes at that depth form one parallel batch.
- Fetch in parallel: The whole level is fetched together in one round-trip.
- Form next level: Their neighbors become the next depth level.
The traversal therefore advances level by level rather than node by node.
Why DFS cannot batch
Depth-first traversal commits to one path. It must complete that path before starting another.
That dependency is the problem. You cannot request the next node until the current one comes back.
- BFS
- DFS
So DFS produces a chain of sequential calls, one after another, with no chance to group them.
Counting the round-trips
This is where the difference becomes measurable.
Sequential traversal costs N round-trips, one for every node you visit. Batched traversal costs only a few, roughly one per depth level.
- Nodes to visit
- Can nodes be grouped?: Only nodes at the same depth level can go in one batch.
- Parallel batch: One call per depth level.
- Sequential call: Finish this node before requesting the next.
- A few round-trips
- N round-trips
- next node
Reducing N sequential calls to a few parallel ones is the entire performance argument.
Latency is the hidden cost
Both traversals may touch the same number of nodes. The work is not what differs.
What differs is latency: the waiting time of each network round-trip.
BFS overlaps that waiting across a whole level. DFS pays it one node at a time.
Putting it to work
When your graph lives behind a network, prefer breadth-first order.
Group each depth level, issue the calls in parallel, then move down. You trade N sequential round-trips for a handful.
- Start level: Begin with the starting node as your first depth level.
- Group batch: Collect every node at that depth into one batch.
- Call parallel: Issue the whole batch as parallel calls in one round-trip.
- Descend: Use the returned neighbors as the next depth level and repeat.
Keep DFS for local, in-memory graphs where a path can be followed without paying for network calls.
Check yourself
In a distributed graph, can traversing one hop require a network round-trip?
- Yes
- No
Answer: Yes
Yes. When nodes or neighbors reside on different machines, a hop may require a request and response across the network.
BFS advances through a distributed graph by processing one _____ at a time and issuing that level's requests in _____.
Answer: BFS advances through a distributed graph by processing one depth level at a time and issuing that level's requests in parallel.
BFS groups nodes by depth and fetches the nodes in each group together. This enables concurrent requests within a level.
A distributed graph has 1,000 visited nodes arranged across 5 depth levels. Which estimate best describes the network waiting difference between sequential traversal and BFS batching?
- About 1,000 versus about 5 round-trips
- About 5 versus about 1,000 round-trips
- About 1,000 versus zero round-trips
- About 500 versus about 500 round-trips
Answer: About 1,000 versus about 5 round-trips
Sequential traversal costs about 1,000 round-trips, one per visited node. BFS batching costs roughly 5 round-trips, one per depth level, while requests within each level overlap.
Keep going
This is lesson 1 of 8 in Netflix Real-Time Distributed Graph: Query Engine Design. Next up:
- From sequential calls to parallel batches
- Why thread-per-request doesn't scale
- 16-24 threads serving thousands of concurrent queries
- The problem with uniform TTLs
- Mapping TTL to data change rate
Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.