Chapter 1, scenario 1, page 7
Rank failing endpoints from distributed CI logs
Target level: Senior. Likely round: coding and practical engineering.
The prompt
You receive log records from hundreds of parallel API tests. Write a utility that returns the endpoints causing the most failures, while handling malformed records, duplicate retries, and files too large to hold comfortably in memory.
The ninety-second answer
“I would not sum a column, because retries and malformed lines would corrupt the count. First I define a normalised failure: a run, a test, an endpoint, and a failure fingerprint. I stream the file line by line so memory is bounded by the number of distinct endpoints, not the number of records. Bad lines go to a separate error channel and get counted, they never stop the job. I collapse retries by treating one test failing the same way inside one run as a single failure, and I normalise dynamic path segments so /orders/8412 and /orders/9317 land in the same bucket. Then I take the top k with a bounded heap and return counts alongside sample trace ids, so the ranking is actionable rather than just a leaderboard.”
