Top 4 Golang Interview Questions
Browse 4 real-world technical and behavioral interview questions about Golang. Review scenarios, edge cases, and architectural best practices.
Your function returns nil on the success path, the caller checks err != nil, and the check fires anyway. What happened?
A Go interface is non-nil when it holds a concrete type, even if the concrete pointer value is nil. Returning a typed nil pointer as an error creates an interface value that fails err == nil checks.
Go gives you no project layout and no dependency-injection container. How do you structure a service so it stays testable as it grows?
Wire dependencies explicitly through constructors from one place in main, define narrow interfaces where they are consumed rather than implemented, and keep handlers thin enough that the logic beneath is testable without a server. With no framework, these are decisions rather than defaults.
Memory keeps climbing in a Go service under load. How do you find out why, and what can you actually tune?
Take a heap profile and compare two taken minutes apart, because the shape of the growth tells you whether it is a leak, a cache with no bound, or simply the collector letting the heap grow. The two real knobs are GOGC and GOMEMLIMIT, and reducing allocation matters more in Go than in a generational runtime.
Several producers write to one channel and one consumer reads it. Who closes the channel?
In Go, the sender closes a channel when no more values will be sent; receivers do not close it just because they are done. Multiple senders need coordination so close happens exactly once after all sends finish. Use this channels answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects goroutines to the point an interviewer is testing.