Count paths in a map, copy into []KV, sort by count descending with cmp.Compare, truncate to n. Scanner buffer raised to 1MB for long lines; malformed lines (<3 fields) are skipped. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012MpK9niZm4jcs3mAJbxMfi
Go SRE Interview Gym
A monorepo of hands-on exercises covering what actually gets asked in Go live-coding rounds for SRE roles. Each numbered folder is self-contained:
main.go— the assignment (in comments) + a scaffold with TODOs and a small runnable demomain_test.go— the interviewer: tests that define "correct", including the traps (goroutine leaks, races, boundary conditions)README.md— the deep dive: why the idiom exists, what breaks in production, and the follow-up questions interviewers reach for
Setup
Go ≥ 1.22 required (loop-variable semantics), any recent toolchain is fine — built and verified against go 1.27. Pure stdlib, zero dependencies.
Workflow
# pick an exercise, read the assignment in main.go, implement the TODOs
go test -race ./01-url-health-checker/ # -race ALWAYS. non-negotiable.
# run everything you've solved so far
go test -race ./...
# some exercises have benchmarks worth exploring
go test -bench=. -cpu=1,4,8 ./09-safe-counter/
Interview-realistic rules: timer set to 30 min, no autocomplete, no LSP if you're brave, and narrate your reasoning out loud — the talking is graded as much as the code.
The ladder
| # | Exercise | Core skill | Freq in interviews |
|---|---|---|---|
| 01 | url-health-checker | bounded concurrency, ctx, HTTP hygiene | ★★★★★ |
| 02 | worker-pool | channel closing protocol, WaitGroup | ★★★★★ |
| 03 | rate-limiter | lazy state, mutex, monotonic time | ★★★★☆ |
| 04 | log-topn | streaming, Scanner limits, map→sort | ★★★★☆ |
| 05 | lru-cache | map+list composite, O(1) design | ★★★★☆ |
| 06 | retry-backoff | jitter, ctx-aware sleep, error classes | ★★★☆☆ |
| 07 | fan-in | leak-free cancellation, nil-channel trick | ★★★☆☆ |
| 08 | graceful-shutdown | signals, Shutdown ctx inversion, k8s | ★★★☆☆ |
| 09 | safe-counter | mutex vs atomic vs sharding, -race | ★★★★☆ (as warm-up) |
| 10 | gotchas | "what does this print" trivia round | ★★★★★ |
Suggested order: 09 → 02 → 01 → 03 → 05 → 04 → 06 → 07 → 08, with gotchas (10)
sprinkled daily. 09 first because it calibrates you on -race; 01/02 are the
highest-yield; 08 is the best conversation generator in on-sites.
Ground rules baked into the tests
- Tests use timeouts to catch deadlocks and missing
close()— a hanging test is a failing test with extra steps. - Several tests count goroutines or track peak concurrency with atomics — read them after solving; test-writing techniques are interview material too.
- Everything must pass under
-race. A green test that fails-raceis red.
Note on the gotchas folder
10-gotchas/* are predict-then-run programs: ex02 deadlocks on purpose, ex11
doesn't compile on purpose. Run them individually (go run ./10-gotchas/ex01-loopvar/),
not as part of go build ./.... Answers are collapsed in 10-gotchas/README.md.