Go (Golang): language, goroutines, channels and services – Server Side interview prep

261 interview-style multiple-choice questions on Go (Golang): language, goroutines, channels and services, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 101 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 11.1 Language basics: types, variables and control flow
  2. 11.2 Errors, defer, panic and recover
  3. 11.3 Slices, maps, strings and arrays
  4. 11.4 Structs, methods, interfaces and generics
  5. 11.5 Goroutines and channels
  6. 11.6 Synchronization, context and concurrency patterns
  7. 11.7 Standard library: HTTP, JSON and I/O
  8. 11.8 Modules, tooling and testing
  9. 11.9 Runtime, performance and production Go

Key terms

11.1 Language basics: types, variables and control flow

Short variable declaration
`:=` declaring and inferring a type
iota
Counter in const blocks
Untyped constant
Constant that adapts to the needed type
Blank identifier
`_` that discards a value
Shadowing
Inner declaration hiding an outer one
init function
Package setup before main
internal package
Import-restricted package
rune
int32 Unicode code point
Type alias
Another name for the same type

11.2 Errors, defer, panic and recover

error value
Go's convention of returning errors as values
defer
Runs a call when the function returns
Exported name
Identifier starting with an uppercase letter
Zero value
Default value of an uninitialized variable
Error wrapping
Adding context while keeping the cause
errors.Is
Matching a value anywhere in the chain
errors.As
Extracting a typed error from the chain
Sentinel error
Predefined error value
errors.Join
One error wrapping several
panic
Abrupt stop for unrecoverable problems
recover
Regaining control in a deferred call
Must function
Helper that panics on error

11.3 Slices, maps, strings and arrays

Slice
Growable view over an underlying array
Map
Built-in hash table
Interface
Set of methods satisfied implicitly
Embedding
Composing a struct by including another type
Slice header
Pointer, length and capacity
Capacity
Room before the array must grow
Full slice expression
a[low:high:max] limiting capacity
Nil slice
Slice with no backing array
slices package
Generic slice helpers
Iterator (iter.Seq)
Function you can range over
Empty struct
Zero-size type
strings.Builder
Efficient string building
clear
Built-in to empty maps or zero slices

11.4 Structs, methods, interfaces and generics

Struct embedding
Including a type so its members are promoted
Method set
Methods a type has for interface checks
Type assertion
Getting a concrete value from an interface
Type switch
Switching on an interface's dynamic type
Interface assertion
Compile-time implementation check
Stringer
Interface with String() string
Type parameter
Generic placeholder type
cmp.Ordered
Constraint for types supporting <
Underlying type constraint
~T matching defined types
Functional options
Variadic config functions

11.5 Goroutines and channels

Goroutine
Lightweight runtime-managed thread
Channel
Typed conduit for communication between goroutines
select
Waits on multiple channel operations
context.Context
Carries cancellation, deadlines and request values
Buffered channel
Channel with queue capacity
Closed channel
Channel that yields zero values after draining
Directional channel
Send-only or receive-only type
Done channel
Closed to broadcast cancellation
GOMAXPROCS
Threads running Go code at once
G-M-P
Go scheduler model
Asynchronous preemption
Runtime interrupting long-running goroutines
Worker pool
Fixed goroutines draining a jobs channel

11.6 Synchronization, context and concurrency patterns

sync.Mutex
Mutual exclusion lock
sync.RWMutex
Many readers or one writer
WaitGroup
Waiting for goroutines to finish
errgroup
Goroutine group returning the first error
Typed atomics
atomic.Int64 and friends
sync.Pool
Reusable temporary objects
context.WithTimeout
Context with a deadline
WithoutCancel
Context that ignores parent cancellation
singleflight
Deduplicating concurrent calls
synctest
Testing concurrency with fake time
goleak
Detecting leaked goroutines in tests

11.7 Standard library: HTTP, JSON and I/O

go.mod
Module definition and dependency file
net/http
Standard HTTP client and server package
Table-driven test
One test looping over a table of cases
Struct tag
Field metadata used by encoders
Handler
Interface with ServeHTTP
HandlerFunc
Function adapted into a Handler
Middleware
func(http.Handler) http.Handler
Graceful shutdown
Finishing requests before exit
PathValue
Reading a route wildcard
slog
Structured logging package
go:embed
Embedding files in the binary
httptest
Testing helpers for HTTP code
html/template
Context-aware escaping templates
sql.DB
Concurrent-safe connection pool

11.8 Modules, tooling and testing

go.sum
Module checksums
Minimal version selection
Pick the highest required minimum
Semantic import versioning
Major version in the import path
Go workspace
Multi-module local development
toolchain directive
Auto-selected Go toolchain version
tool directive
Tracking dev tools in go.mod
govulncheck
Reachability-aware vulnerability scanner
b.Loop
Benchmark loop helper
Fuzz test
Generated inputs to find bugs
Build constraint
Condition for including a file

11.9 Runtime, performance and production Go

Escape analysis
Deciding stack vs heap allocation
GOGC
GC target percentage
GOMEMLIMIT
Soft memory limit for the runtime
pprof
Go's profiling tool and endpoints
Execution tracer
Timeline of scheduling and GC events
PGO
Profile-guided optimization
Static binary
Executable without libc dependency
benchstat
Statistical benchmark comparison
GODEBUG
Settings for changed runtime behavior
os.Root
Directory-confined file access

Sample practice questions

  1. How does Go decide whether a name is exported from a package?

    1. A `public` keyword placed before the declaration exports it
    2. Uppercase first letter means exported; lowercase is package-private
    3. An `export` list at the top of each source file names them
    4. Everything declared in a package is exported automatically

    Answer: B. Uppercase first letter means exported; lowercase is package-private `fmt.Println` is exported; a function named `helper` is not.

  2. How does Go usually report errors?

    1. By returning `-1` from every function that fails
    2. By printing a message to standard output
    3. By returning an `error` last, checked with `if err != nil`
    4. With `try`/`catch` blocks, as in Java and C#

    Answer: C. By returning an `error` last, checked with `if err != nil` `panic` exists but is reserved for truly unrecoverable situations.

  3. What is the difference between an array and a slice in Go?

    1. Arrays can only hold strings; slices can hold any type
    2. They're identical; "slice" is just another name for array
    3. An array's fixed length is part of its type; a slice is a growable view
    4. A slice has a fixed length; an array can grow with `append`

    Answer: C. An array's fixed length is part of its type; a slice is a growable view Most Go code uses slices.

  4. How does a type satisfy an interface in Go?

    1. Implicitly, by having all its methods
    2. By embedding an abstract base class
    3. By registering itself at program startup
    4. By declaring `implements InterfaceName`

    Answer: A. Implicitly, by having all its methods This makes small interfaces like `io.Reader` very flexible.

  5. What is a goroutine?

    1. A special kind of buffered channel
    2. A separate operating system process with its own memory
    3. A lightweight, runtime-managed thread started with `go`
    4. A function that's evaluated at compile time

    Answer: C. A lightweight, runtime-managed thread started with `go` Goroutines start with small stacks, so programs can run many thousands.

  6. What does the Go race detector (`go test -race`) find?

    1. Deadlocks, which it detects at compile time
    2. Memory leaks, and nothing else, in long-running tests
    3. Unsynchronized concurrent access where one access writes
    4. Slow code paths that would benefit from optimization

    Answer: C. Unsynchronized concurrent access where one access writes Run it in tests and CI.

  7. What does the `net/http` standard library give you?

    1. A SQL database driver for Postgres and MySQL
    2. A template engine for generating CSS
    3. Only an HTTP client, with no server support
    4. A production-ready HTTP server and client

    Answer: D. A production-ready HTTP server and client Go 1.22 added method and wildcard patterns like `GET /items/{id}` to `ServeMux`.

  8. What is `go.mod`?

    1. A Docker configuration for containerizing the module
    2. A test file containing the module's unit tests
    3. The compiled binary that `go build` writes to disk
    4. The file defining a module's path, Go version and dependencies

    Answer: D. The file defining a module's path, Go version and dependencies `go.sum` holds checksums to verify downloaded modules.

  9. Why is Go popular for cloud and infrastructure tools like Docker, Kubernetes and Terraform?

    1. It has no garbage collector, so memory use is predictable
    2. It only runs on Windows, which most cloud servers use
    3. It's interpreted, so these tools need no build step at all
    4. Static binaries, fast startup, built-in concurrency and a strong stdlib

    Answer: D. Static binaries, fast startup, built-in concurrency and a strong stdlib Cross-compiling is as simple as setting `GOOS` and `GOARCH`.

  10. What is the zero value of a declared but uninitialized `int`, `string` and pointer in Go?

    1. A compile error
    2. `nil` for all three
    3. `0`, `""` and `nil`
    4. Random memory contents

    Answer: C. `0`, `""` and `nil` Go always initializes variables to their type's zero value.

Practice all 261 questions

More Server Side