The Computing Series

Real Systems

Googlebot (Google’s web crawler) maintains a URL frontier of billions of URLs, prioritised by estimated page importance and crawl freshness. It is BFS in structure but with a priority queue rather than a plain queue — not pure BFS, but BFS-shaped.

npm and pip both use DFS for dependency resolution. The resolution algorithm also handles version constraints (not just graph connectivity), which converts the problem from O(V+E) to NP-hard in the worst case (SAT problem). Both package managers use heuristics to avoid the worst case.

Python’s garbage collector uses a combination of reference counting (immediate collection when count drops to zero) and a cyclic GC (BFS/DFS to collect reference cycles that reference counting cannot handle). The cyclic GC runs periodically, not on every allocation.


Concept: BFS and DFS in Production Systems

Thread: T3 (Graphs) ← graph theory (Book 1) → network topology, service mesh (Book 3); T4 (Queues) ← FIFO/LIFO (Book 1) → message brokers (Book 3)

Core Idea: BFS (queue-based, level-by-level) finds shortest paths and explores nearest nodes first. DFS (stack-based, depth-first) explores complete paths before backtracking. Both require a visited set to handle cycles. Production BFS adds prioritisation, politeness, and frontier management; production DFS adds cycle detection via two sets (visiting + visited) and iterative implementation to avoid stack overflow.

Tradeoff: AT3 — Simplicity vs. Flexibility (recursive DFS is simple but stack-limited; iterative DFS is safe but more complex; BFS is always iterative but requires explicit frontier management)

Failure Mode: FM3 — Unbounded Resource Consumption (BFS frontier grows with graph width; DFS call stack grows with graph depth; both need explicit limits in production)

Signal: When you need the nearest or most important nodes first — BFS. When you need complete paths before backtracking, or need topological ordering — DFS. When the graph has cycles — both require a visited set.

Maps to: Reference Book, Framework 1 (Mental Models — Networks), Framework 8 (Infrastructure — Web Servers, Service Discovery)


Read in the book →