Tech

Go

Go (Golang) is a statically-typed, compiled language designed at Google for building fast, reliable, and concurrent software. Its simplicity, built-in goroutines and channels for concurrency, and efficient standard library make it a top choice for microservices, cloud infrastructure, CLI tools, and distributed systems. Interviews focus on the ownership model, concurrency patterns, interfaces, error handling, and Go's unique approach to polymorphism.

What you get

Questions

20

Difficulty

3 levels

Answer Formats

2

Use the toggle on each card to move between an interview-ready answer and a simpler explanation. Questions are sorted from beginner to advanced, and the keywords are highlighted. You can also blur the answers to practice recalling them from memory.

Questions

Practice the answers out loud.

All topics

Question 1

What is Go and what are its key features?

Beginner

How to answer in an interview

Go, also known as Golang, is a statically-typed, compiled programming language designed at Google. Key features include a simple and clean syntax, built-in concurrency via goroutines and channels, garbage collection, fast compilation, and a powerful standard library. It excels at building networked services, CLI tools, and distributed systems.

Question 2

What are slices in Go and how do they differ from arrays?

Beginner

How to answer in an interview

Slices are dynamic, flexible views into an underlying array, with a length and capacity that can change as elements are added or removed. Arrays in Go have a fixed size determined at compile time and cannot be resized. Slices are far more commonly used because of their flexibility, and they're passed by reference (as a header containing a pointer, length, and capacity) rather than by value.

Question 3

What is the defer keyword used for in Go?

Beginner

How to answer in an interview

The defer keyword schedules a function call to be executed after the surrounding function returns, typically used for cleanup tasks like closing files or releasing locks. Defers are evaluated immediately when the defer statement is encountered but executed in LIFO (last-in, first-out) order after the function returns.

Question 4

How does error handling work in Go?

Beginner

How to answer in an interview

Go uses explicit error handling via the built-in error interface, where functions return an error as an additional return value that must be checked by the caller. There are no exceptions or try/catch blocks. Common patterns include returning nil for no error, wrapping errors with context using fmt.Errorf, and comparing against sentinel errors using errors.Is or errors.As.

Question 5

What are Go modules and why are they used?

Beginner

How to answer in an interview

Go modules are the official dependency management system for Go, introduced to replace GOPATH-based workflows. A go.mod file defines the module's path and its dependencies with specific versions, while go.sum records cryptographic checksums to ensure reproducibility. Modules allow precise version pinning, private repository support, and vendoring.

Question 6

What are blank identifiers and named returns in Go?

Beginner

How to answer in an interview

The blank identifier (_) is used to ignore values you don't need, such as when a function returns two values but you only need one. Named return values pre-declare return variables with their names, allowing you to return implicitly without explicit return values and to use naked returns for short functions, though explicit returns are generally preferred for clarity.

Question 7

What is the difference between strings and []byte in Go?

Beginner

How to answer in an interview

Strings in Go are immutable sequences of bytes, typically representing UTF-8 text. A []byte is a mutable slice of bytes. Converting between them involves a copy (strings(b) or []byte(s)) because they have different memory layouts and mutability semantics. Strings are preferred for text; []byte for raw binary data or when mutation is needed.

Question 8

What are goroutines and how do they differ from OS threads?

Intermediate

How to answer in an interview

Goroutines are lightweight concurrency primitives managed by the Go runtime, not the operating system. They start with a small stack (a few KB) that grows and shrinks as needed, and thousands can run on a single OS thread. OS threads are heavier, with larger fixed stacks and higher context-switching costs managed by the kernel.

Question 9

What is the difference between a channel and a mutex in Go?

Intermediate

How to answer in an interview

Channels are used for communication and synchronization between goroutines, following the philosophy 'don't communicate by sharing memory; share memory by communicating.' A mutex (mutual exclusion lock) protects shared data by ensuring only one goroutine accesses it at a time. Channels are preferred for coordinating work, while mutexes protect critical sections when shared state is necessary.

Question 10

Explain interfaces in Go and how they differ from other languages.

Intermediate

How to answer in an interview

In Go, interfaces are satisfied implicitly — a type implements an interface simply by having the required methods, with no explicit 'implements' keyword needed. This is different from languages like Java or C# where classes must explicitly declare which interfaces they implement. Go interfaces tend to be small and focused, often containing just one or two methods.

Question 11

What is the difference between a value receiver and a pointer receiver in Go?

Intermediate

How to answer in an interview

A value receiver method operates on a copy of the value, so any modifications inside the method don't affect the original value. A pointer receiver method operates on a pointer to the original value, allowing the method to modify the receiver. Pointer receivers are also more efficient for large structs since they avoid copying the entire struct.

Question 12

Explain the select statement in Go.

Intermediate

How to answer in an interview

The select statement blocks until one of its cases can proceed, then executes that case. It's used to multiplex across multiple channel operations, choosing whichever channel is ready first. If multiple cases are ready, one is chosen pseudo-randomly. A default case makes select non-blocking, executing immediately if no channel operation is ready.

Question 13

What is the context package used for in Go?

Intermediate

How to answer in an interview

The context package carries deadlines, cancellation signals, and request-scoped values across API boundaries and goroutine chains. It allows parent operations to cancel child goroutines when a request times out or the client disconnects, preventing resource leaks. Context is typically passed as the first argument to functions performing I/O or RPC calls.

Question 14

What is the sync package and when would you use it?

Intermediate

How to answer in an interview

The sync package provides concurrency primitives for cases where goroutines and channels aren't the best fit. sync.Mutex and sync.RWMutex protect shared state from concurrent access. sync.WaitGroup lets you wait for a collection of goroutines to finish. sync.Once ensures a function runs exactly once across all goroutines, useful for initialization.

Question 15

What is the purpose of the embed package in Go?

Intermediate

How to answer in an interview

The embed package allows Go programs to embed static files, templates, or other assets directly into the compiled binary at build time using the //go:embed directive. This eliminates the need to distribute separate asset files alongside the binary and is useful for configuration files, default templates, and small datasets that should be bundled with the application.

Question 16

What are function closures and how are they used in Go?

Intermediate

How to answer in an interview

Closures in Go are anonymous functions that capture and use variables from their enclosing lexical scope. They're commonly used for callbacks, goroutine arguments, stateful iteration, and customizing behavior without defining a full named function. Closures can also capture and modify variables, creating shared mutable state.

Question 17

How do you test and benchmark Go code?

Intermediate

How to answer in an interview

Go has a built-in testing package. Test functions start with Test and accept *testing.B. Benchmark functions start with Benchmark and accept *testing.B, using b.N for iteration count. Run tests with go test, benchmarks with go test -bench, and race detection with -race. Table-driven tests are a common Go idiom for testing multiple cases cleanly.

Question 18

What are type assertions and type switches in Go?

Intermediate

How to answer in an interview

A type assertion extracts the underlying value from an interface, using the syntax x.(T). If the interface doesn't hold that type, it panics unless you use the comma-ok idiom (v, ok := x.(T)). A type switch lets you branch on the underlying type of an interface value in a switch-like structure, making it cleaner to handle multiple possible types.

Question 19

How does Go handle memory management and garbage collection?

Advanced

How to answer in an interview

Go uses an automatic tricolor mark-and-sweep garbage collector that runs concurrently with the application, minimizing pause times. The compiler performs escape analysis at build time to determine whether variables should be allocated on the stack (fast, automatic cleanup) or heap (needs GC). Stack allocation is strongly preferred, and the GC is optimized for low-latency concurrent workloads.

Question 20

What is the go generate command?

Advanced

How to answer in an interview

go generate runs commands specified in //go:generate comments within Go source files, commonly used for code generation tasks like generating stringer methods, mock implementations, or protobuf bindings. It's not run automatically during build — you must explicitly invoke go generate, and the generated code is checked into version control.

More in Tech

Keep browsing related topics.

Browse all