99 Golang interview questions with answers
99 Golang interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Golang interview questions
What is Go (Golang)? Why should you learn it?
How many ways can you declare variables in Go?
What are the basic data types in Go?
What is the zero value in Go?
How are functions declared in Go?
When are multiple return values used in Go?
How do packages and imports work in Go?
Does Go have classes? What is a struct?
What are pointers in Go? When should you use them?
What is the difference between arrays and slices in Go?
How do maps work in Go?
How is the range loop used in Go?
How is error handling in Go different from JS/Python?
When are defer, panic, and recover used in Go?
How do interfaces work in Go?
When should you use the empty interface (any) in Go?
What are type assertions and type switches?
What is the difference between pointer receivers and value receivers?
How do generics work in Go 1.18+?
What is a goroutine? How is it different from a thread?
What are channels in Go? How are they used?
What is the select statement used for?
When should you use a WaitGroup?
When should you use Mutex and RWMutex?
What is the context package used for?
What is the worker pool pattern in Go?
When should you use errgroup?
How do you write a basic HTTP server in Go?
What is the Gin framework? How does it compare to net/http?
How do you write middleware in a Go HTTP server?
How does JSON encoding and decoding work in Go?
How is GORM used in Go?
What are the best practices for database connections in Go?
What are Go modules? How does go.mod work?
When should you use gRPC in Go?
How do you implement graceful shutdown in a Go server?
How do you implement a rate limiter in Go?
How do you write tests in Go?
What are table-driven tests in Go?
How does benchmark testing work in Go?
How do you mock/stub in Go?
What tools are included in the Go toolchain?
How do you profile a Go application?
What is the functional options pattern in Go?
How is dependency injection done in Go?
What is the pipeline pattern with channels in Go?
What are Go production best practices?
How do you optimize a Docker image for a Go app?
What do you use for structured logging in Go?
Go vs Node.js: when should you choose Go?
What are struct tags in Go and how are they used?
What are the comparable constraint and type sets in Go generics?
What is the difference between errors.Is and errors.As?
Sentinel errors vs custom error types — when to use which?
What does t.Helper() do in Go testing?
What is go test -race? When should you run it?
How do you add Prometheus metrics observability to a Go service?
gofmt vs goimports vs golangci-lint — what's the difference?
In Go, how do `byte` and `rune` differ?
What is a variadic function in Go, and how does the `...` operator work?
How do `new` and `make` differ in Go?
What is the `init` function, and how does package initialization order work in Go?
What is `iota`, and how do you use it with typed constants to build enums?
What is the empty struct `struct{}`, and when should you use it?
Why does an `error` holding a nil pointer not equal `nil` in Go?
What is slice aliasing, and how do `append`/`copy` create pitfalls?
How do you sort a slice of structs with `sort.Slice`?
How do buffered and unbuffered channels differ? When does Go report `all goroutines are asleep - deadlock`?
What does `close(ch)` do? What happens when you send to or receive from a closed channel?
What is the `default` branch in `select` for? What is the common trap with it?
Why must you always call `defer cancel()` after `context.WithTimeout` / `WithCancel`?
What is a goroutine leak? What are the most common causes?
What happens when you send to or receive from a `nil` channel? Why would anyone set a channel to `nil` on purpose?
How do you stop a goroutine pipeline mid-flight? How does a `done` channel differ from `ctx.Done()`?
You have 10,000 URLs to call. How do you cap it at 20 concurrent requests?
What problem does `sync.Once` solve? What happens if the function inside `once.Do` panics?
What kind of data belongs in `context.WithValue`? Why should the key not be a `string`?
What are the common mistakes when using `sync.WaitGroup`?
Why must a `sync.Mutex` never be copied? How does `go vet` catch this?
When is `RWMutex` not faster than `Mutex`? Why can nested `RLock` calls deadlock?
How does a data race differ from a race condition? What does the Go memory model say — is there such a thing as a benign race?
How does Go's G-M-P scheduler work? What should `GOMAXPROCS` be inside a container?
You suspect a Go service is leaking goroutines in production. How do you investigate?
What is the difference between `http.Handler` and `http.HandlerFunc`?
In `fmt.Errorf`, how does `%w` differ from `%v`? When should you wrap an error?
What is struct embedding in Go? Is it inheritance?
What is wrong with `defer` inside a loop, and how do you fix it?
Why should production not run on the default `http.ListenAndServe`? How do you configure timeouts?
When chaining several `func(http.Handler) http.Handler` middlewares, what is the execution order?
Why does assigning a struct value to an interface fail with "method has pointer receiver"?
Does map iteration in Go preserve order? How do you get stable output?
What do `t.Run` subtests add to a table-driven test, and what is the `t.Parallel` trap?
How does `omitempty` work in a struct tag, and why does it not drop an empty struct?
Are `string` and `[]byte` conversions expensive? When should you avoid them?
When should you **not** use generics in Go? What are the decision criteria?
What is escape analysis, and how do you tell whether a variable lands on the stack or the heap?
What problem does `sync.Pool` solve? When should you use it and when not?
What makes a Go benchmark produce meaningless numbers, and when do you call `b.ResetTimer`?
A Go service shows abnormal CPU/RAM in production — how do you investigate with pprof?