HTTP API Crawling and URL Mazes
Asked of: Software Engineer
Last updated
What's being tested
These problems test graph traversal under an I/O contract: traverse a hidden graph exposed as HTTP links, detect termination, and avoid cycles while accounting for network faults. Interviewers probe algorithmic choices (BFS vs DFS), state management (visited/idempotency), and resilient HTTP client behavior.
Patterns & templates
-
BFS traversal using a
dequequeue: guarantees shortest API-hop path to an exit; memory O(V), calls up to O(V+E). -
DFS (iterative stack) for lower memory in deep-but-sparse mazes; beware recursion limits and hidden cycles.
-
Cycle detection / visited set — store canonicalized URLs (strip fragments/params if contract allows) to avoid infinite loops and duplicate calls.
-
Retry with exponential backoff on transient
HTTP 5xxerrors, e.g., 100ms→200ms→400ms, cap retries to avoid long tails. -
Timeouts & overall budget — per-request timeout (e.g., 2s) plus global deadline; abort if cumulative time > budget to prevent blocking CI.
-
HTTP client best-practices — reuse
requests.Sessionoraiohttpconnector, propagateAuthorizationheader, and handle non-JSON bodies and unexpected status codes.
Common pitfalls
Pitfall: Repeatedly re-requesting the same URL without normalization; leads to infinite loops and flakey
p99latencies.
Pitfall: Retrying on client errors (
4xx) instead of only transient server errors (5xx) — wastes budget and hides bugs.
Pitfall: Forgetting a global timeout — a slow endpoint can stall the whole traversal and fail the job.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Practice questions
- Navigate a Maze Through a Next-Step APIRamp · Software Engineer · Technical Screen · medium
- Find an Exit in a URL MazeRamp · Software Engineer · Technical Screen · medium
- Find final URL by crawling until “congrats”Ramp · Software Engineer · Technical Screen · hard
- Find exit URL via BFS API callsRamp · Software Engineer · Technical Screen · medium
- Navigate maze via HTTP APIRamp · Software Engineer · Technical Screen · medium
Related concepts
- Web Crawlers, URL Normalization, And PolitenessSystem Design
- Graph Search, State Space, And Path OptimizationCoding & Algorithms
- Graph, Grid, BFS/DFS, And Union-FindCoding & Algorithms
- DFS/BFS Tree, Graph, And Grid TraversalCoding & Algorithms
- Graph Search And Weighted PathsCoding & Algorithms
- Graph Traversal And Shortest PathsCoding & Algorithms