# go

// [38] real interview questions. Answers and sources live in the practice app.

practice this topic
  1. Why are goroutines cheaper than OS threads, and what makes 'just spawn a goroutine' idiomatic in Go?(mid)
  2. When do you use an unbuffered vs a buffered channel, and what do channels give you beyond a queue?(mid)
  3. A function returns *MyError as error, returns nil on success, yet callers' err != nil checks fire. Explain the nil interface trap.(senior)
  4. What are the three rules of defer, and what practical gotchas follow from them?(mid)
  5. How do panic and recover work, and when is recover legitimate in production Go?(mid)
  6. Why doesn't Go have exceptions, and how does idiomatic error handling work instead?(mid)
  7. How does context.Context propagate cancellation, and what are the conventions for using it?(mid)
  8. A teammate wants to pass the database handle and logger through context.Value. What do you tell them?(senior)
  9. Two slices in your code seem to mutate each other's data. Explain how slices share backing arrays and how append makes it worse.(senior)
  10. How can a tiny slice keep a huge amount of memory alive, and what is the fix?(senior)
  11. Should methods be defined on value receivers or pointer receivers? What drives the choice?(mid)
  12. What happens with closures launched as goroutines inside a loop — and how did Go 1.22 change the answer?(mid)
  13. Your service crashes with 'fatal error: concurrent map writes'. Why aren't Go maps thread-safe, and what are your options?(mid)
  14. What are zero values in Go, and how do they shape API design?(junior)
  15. Why can't you pass a []string directly to a function expecting []interface{}?(mid)
  16. How does Go manage memory — what roles do the garbage collector and escape analysis play?(mid)
  17. Concurrency is not parallelism — what does that mean in Go terms?(mid)
  18. Your Go server's goroutine count climbs steadily and never comes down. What causes goroutine leaks and how do you prevent and find them?(senior)
  19. A Go service's CPU usage doubled after a release. Walk through profiling it with pprof in production.(senior)
  20. Since Go 1.18 your team can use generics. What is the official guidance on when type parameters help and when they are the wrong tool?(mid)
  21. One teammate guards everything with channels 'because it's idiomatic Go'; another uses mutexes everywhere. For a shared in-memory cache and for a work pipeline, what do you actually choose?(mid)
  22. How do you implement graceful shutdown for a Go HTTP service running in Kubernetes?(mid)
  23. When do you wrap an error with %w versus %v — and why is wrapping sometimes deliberately the wrong choice?(senior)
  24. A Go service in Kubernetes has a CPU limit of 2 cores on a 64-core node, and latency is awful with mysterious multi-millisecond stalls. Connect this to GOMAXPROCS.(senior)
  25. Your Go pod's RSS keeps climbing. How do you tell a real memory leak from normal GC behavior, and what knobs exist?(senior)
  26. You need to call 20 downstream APIs concurrently for one request: first error should cancel the rest, and concurrency must be capped at 5. What's the idiomatic structure?(mid)
  27. What does Go's race detector actually detect, what does it miss, and where in your pipeline should it run?(mid)
  28. Why was time.After inside a hot select loop a known memory problem, and how did Go 1.23 change the story?(mid)
  29. How should a Go package design its exported errors so callers can react to them without brittle string matching?(mid)
  30. What actually makes an interface value nil in Go, and how does that shape when interfaces should be small?(mid)
  31. A goroutine reads a boolean flag another goroutine writes, with no synchronization; it works on your laptop but hangs in production. Why is this a bug even though the flag is 'just a bool'?(senior)
  32. sync.WaitGroup, errgroup, and a done-channel all coordinate goroutines. For 'wait for N workers to finish', which do you pick and what are the classic WaitGroup mistakes?(mid)
  33. How do you write table-driven tests with subtests in Go, and what do t.Run, t.Parallel, and t.Cleanup give you?(mid)
  34. You must call a flaky downstream with a per-attempt timeout, an overall deadline, retries with backoff, and correct cancellation. How do you compose context correctly?(senior)
  35. When is sync.Pool the right tool, and what are its non-obvious rules that make people misuse it?(mid)
  36. How does Go modules' version selection actually work, and how do go.mod, go.sum, and semantic import versioning keep builds reproducible?(mid)
  37. Producers keep pushing to a channel that consumers drain slower, and memory or latency climbs. How do you design backpressure in a Go pipeline?(senior)
  38. sync.Once, init(), and lazy singletons all set up shared state once. When do you use each, and what are the pitfalls?(mid)