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
- 11.1 Language basics: types, variables and control flow
- 11.2 Errors, defer, panic and recover
- 11.3 Slices, maps, strings and arrays
- 11.4 Structs, methods, interfaces and generics
- 11.5 Goroutines and channels
- 11.6 Synchronization, context and concurrency patterns
- 11.7 Standard library: HTTP, JSON and I/O
- 11.8 Modules, tooling and testing
- 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
How does Go decide whether a name is exported from a package?
- A `public` keyword placed before the declaration exports it
- Uppercase first letter means exported; lowercase is package-private
- An `export` list at the top of each source file names them
- 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.
How does Go usually report errors?
- By returning `-1` from every function that fails
- By printing a message to standard output
- By returning an `error` last, checked with `if err != nil`
- 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.
What is the difference between an array and a slice in Go?
- Arrays can only hold strings; slices can hold any type
- They're identical; "slice" is just another name for array
- An array's fixed length is part of its type; a slice is a growable view
- 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.
How does a type satisfy an interface in Go?
- Implicitly, by having all its methods
- By embedding an abstract base class
- By registering itself at program startup
- By declaring `implements InterfaceName`
Answer: A. Implicitly, by having all its methods This makes small interfaces like `io.Reader` very flexible.
What is a goroutine?
- A special kind of buffered channel
- A separate operating system process with its own memory
- A lightweight, runtime-managed thread started with `go`
- 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.
What does the Go race detector (`go test -race`) find?
- Deadlocks, which it detects at compile time
- Memory leaks, and nothing else, in long-running tests
- Unsynchronized concurrent access where one access writes
- Slow code paths that would benefit from optimization
Answer: C. Unsynchronized concurrent access where one access writes Run it in tests and CI.
What does the `net/http` standard library give you?
- A SQL database driver for Postgres and MySQL
- A template engine for generating CSS
- Only an HTTP client, with no server support
- 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`.
What is `go.mod`?
- A Docker configuration for containerizing the module
- A test file containing the module's unit tests
- The compiled binary that `go build` writes to disk
- 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.
Why is Go popular for cloud and infrastructure tools like Docker, Kubernetes and Terraform?
- It has no garbage collector, so memory use is predictable
- It only runs on Windows, which most cloud servers use
- It's interpreted, so these tools need no build step at all
- 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`.
What is the zero value of a declared but uninitialized `int`, `string` and pointer in Go?
- A compile error
- `nil` for all three
- `0`, `""` and `nil`
- Random memory contents
Answer: C. `0`, `""` and `nil` Go always initializes variables to their type's zero value.
More Server Side
- HTTP fundamentals
- REST API design
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting