SoloMedium5m

The Queue Width Explosion

#marketing-ops — viral referral job OOM killed

Ops: BFS finds users within N degrees for referral bonuses. Pod has 8GB RAM. Script died at level 4 — queue width hit millions. Textbook BFS space is O(W); in a dense graph W = b^d.

The trap: Unbounded BFS on a social graph = exponential memory.

Your task

Fix `find_referral_network()` in `viral_referral.py`: depth-limited BFS — track (node, depth) and stop expanding at MAX_HOPS.

Book: BFS space O(W) · Prod: W = b^d — bound depth or OOM the pod.

Skills you'll prove

algorithmspythonbfsgraph-traversalspace-complexitymemory-managementbackendbook-vs-prod

Interview Tip

When asked about BFS or graph traversal, say: "Textbook BFS space complexity is O(W) where W is max queue width. In a dense social graph where each user has 50 connections, W at depth d is 50^d — that's exponential memory. I debugged a referral job that OOM'd a production worker because it ran unbounded BFS to find all users within 5 degrees. The fix wasn't a bigger server — it was depth-limited BFS aligned with what marketing actually needed. In production, you bound depth or use bidirectional search; you don't traverse the whole graph because the product question is always finite hops."

Browse freely — sign in when you're ready to open a ticket and prove your skills.