Log insights: AI coding interview practice
You’re on call for the API gateway. This library parses access-log lines and feeds the dashboard: busiest endpoints and latency percentiles, refreshed every few seconds while new lines keep arriving. Three tickets are waiting for you.
Download the project (zip, 8 KB)
Java 17, Maven, JUnit 5. Covers parsing, percentiles, time windows, caching with invalidation.
What's inside
pom.xml README.md src/main/java/practice/logs/LogLine.java src/main/java/practice/logs/LogParser.java src/main/java/practice/logs/LogStats.java src/main/java/practice/logs/MalformedLineException.java src/main/java/practice/logs/PathCount.java src/test/java/practice/logs/BaselineTest.java src/test/java/practice/logs/Lines.java src/test/java/practice/logs/Phase1Test.java src/test/java/practice/logs/Phase2Test.java src/test/java/practice/logs/Phase3Test.java
Run it
mvn -q test # phase tests fail until you solve them mvn -q test -Dtest=BaselineTest # what already works; keep it green
How to practise
- Set a 60-minute timer: about 10 minutes for phase 1, 25 for phase 2, 20 for phase 3 and 5 to review.
- Use an AI chat that can read the project files (or paste them in), but type every change yourself. Many AI-enabled rounds work this way: the AI explains and suggests, you edit.
- Say your plan out loud before you prompt, and check every AI answer against the code and the tests before you trust it.
- Run only the phase you’re on, then the whole suite, so you know you didn’t break what already worked.
The three tickets
Phase 1: Fix the bug
On-call says the busiest-endpoints panel is useless: /api/orders is the hottest endpoint and it never shows up. Find the cause and fix it.
Check with mvn -q test -Dtest=Phase1Test
Hint
Look at what the parser stores as the path for a real log line, then at how topPaths groups them.
Phase 2: Add the feature
The dashboard needs an error-rate panel. Implement LogStats.errorRate(from, to): the share of requests in [from, to) that returned a 5xx status, 0 for an empty window, and an error for a backwards window.
Check with mvn -q test -Dtest=Phase2Test
Hint
Pin down the edges first: is a 404 an error here? Is a line exactly at ‘to’ inside the window?
Phase 3: Make it fast
With a day of traffic loaded, the dashboard takes seconds to refresh. Make percentile() and topPaths() fast while lines keep arriving, without changing their answers.
Check with mvn -q test -Dtest=Phase3Test
Hint
The dashboard reads far more often than lines arrive between reads. What work is repeated on every read?
More practice projects
- Inventory reservations: A checkout service that holds stock while shoppers pay. Fix a double-counting bug, add all-or-nothing cart reservations, then make stock checks fast during a sale.
- Rate limiter: A per-key token-bucket rate limiter for an API gateway. Fix a refill bug, add per-customer limits, then make it survive 200,000 keys.
Want to know what real rounds look like first? Read the candidate reports by company.