Go Interview Questions & Tips
Go Interview Stats
We've hosted over 100k interviews on our platform. Go was the language of choice in those interviews 1% of the time, and engineers who interviewed in Go passed their interviews 51% of the time.
Below is a distribution of programming languages and their popularity in technical interviews as well as success rates in interviews, by language.
Go Idioms & Idiosyncrasies
Go, often referred to as Golang, is a statically typed, compiled language renowned for its simplicity, efficiency, and strong support for concurrent programming. Go was developed by Google, and its design makes it an excellent choice for concurrent and networked programming.
Go's distinct features and programming style allow developers to write clear and efficient code. Here are some of the key aspects of Go that are worth flexing in a technical interview:
- Structs and Interfaces: Go employs structs instead of classes and uses interfaces for abstraction and polymorphism. You should be comfortable defining and using structs and interfaces, understanding how to implement interfaces, and the role of embedding in Go.
- Error Handling: Go takes a refreshing approach to errors by eschewing exceptions in favor of explicit error handling. This should be familiar to you from the fact that we pass back two values in functions with the second one being any potential errors in that function. Be familiar with the idiomatic Go error handling using the
error
type and always check errors right after they occur. - Go's Standard Library: Go boasts a robust and feature-rich standard library. Be comfortable using common packages such as
fmt
,net/http
,io
,os
, andsync
as these are common topics of trivia in interviews. - Goroutines and Channels: Understand the concept of goroutines for lightweight thread management and channels for communication between goroutines. Have a good grasp of Go's concurrency model.
- Defer, Panic, and Recover: Go has unique error recovery mechanisms through the use of defer, panic, and recover. Understand how and when to use them.
- Slices and Maps: Slices and maps are key built-in data structures in Go. Be comfortable creating and manipulating slices and maps.
- Go Memory Management: Understand how Go handles memory allocation, and be aware of Go garbage collection.
Common Go Interview Mistakes
When interviewing in Go, there are a few common pitfalls to avoid:
Ignoring Errors
Go doesn't use exceptions for error handling and instead relies on an explicit error return value. Ignoring errors can lead to unpredictable behavior, and it's considered bad practice. Always handle errors right after they occur.
The most common way this crops up is when a candidate ignores the error returned by a function or method:
res, _ := http.Get("http://example.com/")
1
2res, _ := http.Get("http://example.com/")
3
In the above code snippet, the Get function returns two values - a Response and an error. Ignoring the error by using an underscore (_) is bad practice. It's better to handle the error appropriately:
Never ignore an error return value. Here is an example of handling errors correctly:
file, err := http.Get("http://example.com/")
if err != nil {
log.Fatal(err)
}
// continue processing with file
1
2file, err := http.Get("http://example.com/")
3if err != nil {
4 log.Fatal(err)
5}
6// continue processing with file
7
In the corrected example, the error is checked, and if it's not nil, the error is logged, and the application is terminated. This approach makes it easy to see when and where the problem occurred, making debugging easier.
Not Using Concurrency When Appropriate
In coding interviews, concurrency is a topic that does not tend to come up very often. If you're coding in Go and likely applying for a role in Go then expect concurrency as a possible question type. One of the primary benefits of using Go is its built-in support for concurrent programming via goroutines and channels. Ignoring these features and writing strictly sequential code can be a significant oversight and will prevent you from demonstrating your mastery of one of Go's key strengths.
Go's concurrency model, known as CSP (Communicating Sequential Processes), is one of the language's most powerful features. It allows multiple tasks to run independently of each other and provides a way to communicate between them without the need for locks or shared state, which can lead to complex bugs.
The go
keyword in Go is used to launch a new goroutine, which is a lightweight thread of execution. Channels provide a way for these goroutines to communicate safely with each other.
func printNumbers() {
for i := 1; i <= 10; i++ {
fmt.Println(i)
}
}
func printLetters() {
for i := 'a'; i <= 'j'; i++ {
fmt.Println(string(i))
}
}
func main() {
go printNumbers()
go printLetters()
time.Sleep(time.Second)
}
1
2func printNumbers() {
3 for i := 1; i <= 10; i++ {
4 fmt.Println(i)
5 }
6}
7
8func printLetters() {
9 for i := 'a'; i <= 'j'; i++ {
10 fmt.Println(string(i))
11 }
12}
13
14func main() {
15 go printNumbers()
16 go printLetters()
17 time.Sleep(time.Second)
18}
19
In the above example, printNumbers
and printLetters
are executed concurrently. However, not all problems can or should be solved with concurrency, and its misuse can lead to problems like race conditions. Understanding when and how to use these features appropriately is an essential part of Go programming.
Misunderstanding Nil Interfaces
In Go, an interface value is nil
only if both its type and value are nil
. A common mistake is assuming that an interface holding a nil
pointer would itself be nil
, which is incorrect. Here's an illustration:
type Foo struct {}
func (f *Foo) Bar() {}
var f *Foo // f is a nil pointer
var i interface{} = f
if i == nil {
fmt.Println("i is nil")
} else {
fmt.Println("i is not nil") // Output: i is not nil
}
1
2type Foo struct {}
3func (f *Foo) Bar() {}
4
5var f *Foo // f is a nil pointer
6
7var i interface{} = f
8
9if i == nil {
10 fmt.Println("i is nil")
11} else {
12 fmt.Println("i is not nil") // Output: i is not nil
13}
14
In the above example, even though the f
pointer is nil
, the interface i
is not nil
because it has a type (*Foo
). This is a subtle point that often trips up even experienced Go programmers. This mistake can lead to panics at runtime if you try to access a method on i
assuming that it is nil
.
type Fooer interface {
Bar()
}
var f *Foo // f is a nil pointer
var i Fooer = f
if i == nil {
fmt.Println("i is nil")
} else {
fmt.Println("i is not nil") // Output: i is not nil
}
i.Bar() // Runtime panic: nil pointer dereference
1
2type Fooer interface {
3 Bar()
4}
5
6var f *Foo // f is a nil pointer
7
8var i Fooer = f
9
10if i == nil {
11 fmt.Println("i is nil")
12} else {
13 fmt.Println("i is not nil") // Output: i is not nil
14}
15
16i.Bar() // Runtime panic: nil pointer dereference
17
18
In the above example, we define an interface Fooer
that has a Bar
method. f
is a nil
pointer to Foo
, and i
is an interface of type Fooer
which holds f
. Although f
is nil
, i
is not nil
and calling the Bar
method on i
results in a runtime panic as f
is nil
.
Thus, when working with interfaces in Go, it's crucial to understand the distinction between a nil
interface value and an interface value that holds a nil
.
How to Demonstrate Go Expertise in Interviews
While there are many ways to demonstrate mastery over Go in an interview, show that you aren't a Java/C++ coder that happens to be using Go, you're a Go developer with full understanding of what makes Go a unique language.
- Talk about Concurrency: One of the highlights of Go is its native support for concurrent programming with goroutines and channels. Explaining how you've used these features in your past projects can illustrate your understanding of these essential Go concepts. You could say, "I've utilized Go's powerful goroutines and channels to handle multiple tasks concurrently, resulting in more efficient and faster programs."
- Error Handling: Go has a unique way of handling errors compared to other languages. You could talk about how you've implemented error handling using idiomatic Go code. For example, "I've leveraged Go's explicit error handling methodology, always checking for errors where they occur and propagating them up to the appropriate level where they can be handled."
- Interfaces and Type Embedding: Discuss how you've used interfaces for achieving polymorphism in Go and how type embedding has helped create complex types. You might say, "In Go, I've used interfaces extensively to achieve abstraction and polymorphism. I've also found Go's type embedding to be a powerful way to build complex types while avoiding classical inheritance."
- Discuss Go's Simplicity: Go is known for its simplicity and readability. Talk about how you adhere to this philosophy in your code. You can say, "I adhere to Go's philosophy of simplicity, valuing clear and straightforward code over clever one-liners. I believe in writing code that's easy for others (and future me) to read and understand." This can help you stand out from the Pythonistas who write "elegant" (hard-to-read) one-liners and the Java folks that tend to over-engineer and abstract out all common sense from their solutions.
Go Interview Replays
Below you can find replays of mock interviews conducted on our platform in Go. The questions asked in these interviews tend to be language-agnostic (rather than asking about language-specific details and idiosyncrasies), but in these cases, the interviewee chose Go as the language they would work in.

About interviewing.io
interviewing.io is a mock interview practice platform. We've hosted over 100K mock interviews, conducted by senior engineers from FAANG & other top companies. We've drawn on data from these interviews to bring you the best interview prep resource on the web.