ExtraBrain Interview Questions
Go (Golang) Interview Questions for 2026, With Answer Outlines
Short answer
Go interviewers focus on concurrency you can reason about: channel semantics, a worker pool that stops cleanly through context cancellation, error wrapping with errors.Is and errors.AsType, the nil interface trap, slice aliasing and map safety. Expect questions on recent releases too, including WaitGroup.Go in Go 1.25, errors.AsType in 1.26 and generic methods in 1.27.
Golang interview questions for 2026: channels, worker pools, context, errors, nil interfaces, slices, generics and what changed in Go 1.25 to 1.27.
Go interviews tend to be practical. You get a short program with goroutines and channels and are asked whether it leaks, deadlocks or races, then you write a worker pool and the interviewer asks how it shuts down when one job fails. Language trivia matters less than whether your goroutines always have a way to exit.
The release cadence also gives interviewers fresh material. The Go release history lists Go 1.26 on February 10, 2026 and Go 1.27 on August 19, 2026, and both added things worth knowing. One note on testing: Go isn’t installed on the machine used for the other languages in this series, so these snippets were compiled, vetted and run in the official Go Playground on Go 1.27 during review instead. They use only the standard library.
Concurrency questions
What happens when you receive from a closed channel?
package main
import "fmt"
func main() { ch := make(chan int, 2) // buffered: two sends succeed without a receiver ch <- 1 ch <- 2 close(ch)
for v := range ch { // range ends once the channel is closed and drained fmt.Println(v) // 1, then 2 } v, ok := <-ch fmt.Println(v, ok) // 0 false}Receiving from a closed, empty channel returns the zero value immediately with ok == false. Sending on a closed channel panics, and so does closing it twice, which is why the rule of thumb is that only the sender closes a channel. An unbuffered channel blocks the sender until a receiver is ready, so it doubles as a synchronization point.
Write a worker pool that stops on the first error.
package main
import ( "context" "errors" "fmt" "sync" "time")
var errBadInput = errors.New("bad input")
func process(ctx context.Context, job int) (int, error) { select { case <-time.After(10 * time.Millisecond): // stands in for real work if job == 7 { return 0, fmt.Errorf("job %d: %w", job, errBadInput) } return job * job, nil case <-ctx.Done(): return 0, ctx.Err() }}
func main() { ctx, cancel := context.WithCancelCause(context.Background()) defer cancel(nil)
jobs := make(chan int) results := make(chan int)
var wg sync.WaitGroup for range 3 { wg.Go(func() { // Go 1.25+; older code uses wg.Add(1) and defer wg.Done() for job := range jobs { r, err := process(ctx, job) if err != nil { cancel(err) // only the first cause is kept return } select { case results <- r: case <-ctx.Done(): return } } }) }
go func() { // producer defer close(jobs) for i := 1; i <= 10; i++ { select { case jobs <- i: case <-ctx.Done(): return } } }()
go func() { wg.Wait() close(results) }()
sum := 0 for r := range results { sum += r } fmt.Println("partial sum:", sum) // varies by run fmt.Println(errors.Is(context.Cause(ctx), errBadInput)) // true fmt.Println(context.Cause(ctx)) // job 7: bad input}Walk the interviewer through the exits, because that is what they’re checking. Every send and receive that could block also selects on ctx.Done(), so no goroutine waits forever after cancellation. The producer owns jobs and closes it; a separate goroutine closes results only after every worker has returned. sync.WaitGroup.Go, added in Go 1.25, runs the function in a new goroutine and tracks it, replacing the Add and Done pair that people often get wrong. In production, golang.org/x/sync/errgroup packages the same pattern.
What are the rules for using context?
The context package docs are specific: pass a Context explicitly as the first parameter, usually named ctx, rather than storing it in a struct; never pass a nil context; and call the cancel function from WithCancel, WithTimeout or WithDeadline on every path, or the child context leaks until its parent is canceled (go vet checks this). WithCancelCause records why a context was canceled, as in the pool above. Use WithValue only for request-scoped data such as trace IDs, never for optional parameters.
Are maps safe for concurrent use?
No. The Go FAQ explains that map operations aren’t atomic by design, because most maps are used by one goroutine or are already protected by a larger lock. Concurrent reads are fine; a write concurrent with any other access can crash the program. Use a sync.Mutex or sync.RWMutex around a plain map, or sync.Map for narrow cases such as caches that are written once and read many times. Run tests with -race to find these bugs.
When would you use a mutex instead of a channel?
Use a channel when you’re passing ownership of data or signaling between goroutines, as in the pool above. Use a mutex when several goroutines share a piece of state, such as a counter or a cache, and each needs a short critical section. Forcing shared state through a channel adds a goroutine and complexity without making the code safer. Saying “channels for communication, mutexes for state” and then giving one example of each is a solid answer.
How do you find goroutine leaks?
A leaked goroutine is usually blocked forever on a channel nobody will touch again. Prevent it with the patterns above, then detect it: the Go 1.27 release notes make the goroutineleak profile generally available through runtime/pprof and /debug/pprof/goroutineleak. It finds goroutines blocked on primitives that can never be unblocked, though it can miss leaks involving primitives reachable from globals.
Errors and interfaces questions
Why is this error not nil?
package main
import "fmt"
type MyError struct{}
func (*MyError) Error() string { return "my error" }
func find(fail bool) error { var p *MyError // a nil pointer if fail { p = &MyError{} } return p // the interface now holds (type *MyError, value nil)}
func main() { err := find(false) fmt.Println(err == nil) // false fmt.Printf("%T\n", err) // *main.MyError}The Go FAQ answers this one directly: an interface value is a pair of a dynamic type and a value, and it is nil only when both are unset. Returning a typed nil pointer sets the type. The fix is to return a literal nil on the success path.
Value receivers or pointer receivers?
Use a pointer receiver when the method changes the receiver, when the struct is large enough that copying matters, or when it contains something that must not be copied, such as a sync.Mutex. Otherwise a value receiver is fine. Keep one style per type, because method sets differ: a *T has both kinds of methods, while a T value stored in an interface only has the value-receiver ones, which is the usual reason a type “doesn’t implement” an interface.
How do you wrap and inspect errors?
package main
import ( "errors" "fmt" "io/fs" "os")
func loadConfig(path string) error { if _, err := os.ReadFile(path); err != nil { return fmt.Errorf("load config %q: %w", path, err) } return nil}
func main() { err := loadConfig("/does/not/exist.yaml") fmt.Println(errors.Is(err, fs.ErrNotExist)) // true: Is walks the %w chain
if pathErr, ok := errors.AsType[*fs.PathError](err); ok { // Go 1.26+ fmt.Println(pathErr.Op) // open }}%w keeps the original error in the chain, so errors.Is can match a sentinel value and the errors package can extract a typed error. errors.AsType, with the signature func AsType[E error](err error) (E, bool), arrived in Go 1.26 and is now preferred over errors.As because it needs no pointer-to-target variable.
Slices, generics and release questions
Why did appending to one slice change another?
package main
import "fmt"
func main() { base := make([]int, 3, 4) // len 3, cap 4 a := append(base, 1) // fits in capacity: shares base's array b := append(base, 2) // writes the same slot fmt.Println(a[3], b[3]) // 2 2
c := append(base[:3:3], 9) // capacity limited to 3, so append must copy fmt.Println(c[3], a[3]) // 9 2}A slice is a pointer, a length and a capacity. When append fits within capacity it writes into the shared array, so two slices derived from the same base can overwrite each other. The full slice expression s[low:high:max] caps capacity and forces a copy on the next append.
What changed in recent Go releases?
| Release | Change | Question it prompts |
|---|---|---|
| Go 1.22 | Per-iteration loop variables | ”Is capturing i in a goroutine still a bug?” |
| Go 1.25 | Container-aware GOMAXPROCS, WaitGroup.Go | ”How many threads run Go code in a pod?” |
| Go 1.26 | new(expr), Green Tea GC on by default | ”How do you set an optional *int field?” |
| Go 1.27 | Generic methods, encoding/json backed by v2 | ”Why couldn’t methods have type parameters before?” |
The loop variable change applies to modules whose go.mod declares go 1.22 or later. The Go 1.25 notes say GOMAXPROCS now respects a cgroup CPU limit on Linux, the Kubernetes CPU limit rather than the request. The Go 1.26 notes let new take an expression, such as new(yearsSince(born)), and turn on the Green Tea garbage collector by default. Go 1.27 allows method declarations with their own type parameters, while interface methods still can’t declare them.
Practice explaining every exit path
The worker pool is the question to rehearse until you can explain each goroutine’s exit without looking. Say it out loud, then have someone change one requirement (“results must keep input order”) and adapt. Recording practice with ExtraBrain gives you a transcript to check for exits you forgot to mention. The backend developer mock interview page has related prompts, our page on backpressure helps when a pool question turns into system design, and our SQL interview questions cover the database round that usually sits in the same loop. Follow the employer’s rules on AI assistance during the interview itself; ExtraBrain is for preparation and your own notes.
FAQ
Do Go interviews use LeetCode-style problems?
Many do, in Go. Expect slices, maps and sorting with slices.SortFunc, plus at least one question about goroutines or channels.
Should I use generics in an interview answer?
Use them when they remove real duplication, such as a Map or Filter helper. Interfaces are still the idiomatic choice for behavior.
What does defer evaluate immediately?
The arguments. defer fmt.Println(i) captures i when the defer statement runs, and deferred calls execute in last-in, first-out order when the function returns.