GO
157 bites tagged GO — interview questions with model answers, and 60-second explainers.
Design a graceful worker pool in Go
Buffered job channel, fixed worker goroutines, WaitGroup to await in-flight work, context cancellation to stop intake. concurrency coordination with goroutines, channels, and context.
cgo threading challenges with multi-threaded C libraries
Cgo calls run on a dedicated OS thread and detach the P; thread-local state and callbacks into Go are fragile; solutions include LockOSThread, minimizing crossings, and a dedicated… understanding of the Go-to-C boundary and threading.
Cancellation and cleanup: Go context/errgroup vs Tokio
Go propagates cancellation via context.Context that goroutines must poll, with errgroup canceling siblings on first error; Tokio cancels by dropping futures, which stops them at await… structured-concurrency cancellation knowledge.
Go scheduler work-stealing and blocking syscalls
The GMP model runs goroutines (G) on OS threads (M) attached to logical processors (P); idle P's steal half of another P's run queue; on a blocking syscall the M detaches with its G. knowledge of the Go runtime scheduler internals.
Implicit Go interfaces versus explicit Rust trait impls
Go's implicit satisfaction enables decoupling and retrofitting but hides who implements what and risks accidental conformance; Rust's explicit impls aid discovery, refactoring… understanding of conformance models and maintainability.
Go if err != nil versus Rust's ? operator
Go's explicit checks are verbose but make every error site visible; Rust's ? propagates concisely while still forcing the error into the type, reducing boilerplate. judgment on error-handling ergonomics.
Designing a logging abstraction: Go interfaces vs Rust traits
Define a Logger interface/trait with a write method; Go interfaces are always dynamically dispatched; Rust lets you choose static dispatch (impl Trait/generics) or… ability to design polymorphic abstractions and explain dispatch.
Go slices versus Rust Vec growth and reallocation
Both are a (pointer, length, capacity) triple over a heap buffer that reallocates and copies on growth, roughly doubling; key difference is Go slices share backing arrays and have no ownership… understanding of dynamic-array internals.
Go interfaces versus Rust traits and macros at scale
Go uses reflection over interface{} (e.g. encoding/json) for runtime flexibility; Rust uses traits plus derive/proc macros (e.g. serde) for compile-time, zero-cost code generation. connecting language philosophy to ecosystem patterns.
Go's mandatory runtime versus Rust's minimal runtime
Go ships a GC and goroutine scheduler in every binary, ideal for services; Rust has only a tiny runtime and no GC, enabling embedded, kernels, and WASM. understanding of runtime cost and its limits.
Go interface-constraint generics versus Rust trait bounds
Go constrains type parameters with interfaces and may use dictionaries/shape stenciling; Rust uses trait bounds with full monomorphization for zero-cost specialization. understanding of generics design and monomorphization.
Go (T, error) versus Rust Result for error handling
Go returns a separate error value you may ignore; Rust wraps success or error in one Result enum the compiler forces you to handle. Go favors simplicity, Rust favors compile-enforced safety. understanding of explicit error models.
Goroutines and channels versus ownership-based concurrency
Go uses cheap goroutines and CSP-style channels to coordinate by communication; Rust uses ownership plus Send/Sync to make data races a compile error. understanding of two concurrency philosophies.
Structural Go interfaces versus nominal Rust traits
Go interfaces are satisfied implicitly by method shape (structural); Rust traits must be explicitly implemented (nominal). grasp of typing models and their design impact.
Rust lifetimes versus Go garbage-collected lifetimes
A lifetime is a compile-time region a reference is valid for; annotations like 'a relate input and output reference durations; Go instead uses garbage collection and escape analysis. understanding of how Rust tracks reference validity.
Fearless concurrency: Rust compile-time vs Go runtime
Rust uses ownership plus Send/Sync to reject data races at compile time; Go encourages channels but still allows races, with the runtime race detector catching them at test… understanding of where each language catches concurrency bugs.
Architecting an L7 proxy in Go versus Rust
Go offers GC and cheap goroutines for fast delivery but tail-latency GC pauses; Rust offers ownership and async/await for predictable latency at higher complexity. ability to weigh systems trade-offs under real constraints.
Using context.Context across microservice calls in Go
Context carries cancellation, deadlines, and values; pass ctx as first arg, set one WithTimeout at the edge, attach a request ID via WithValue, thread it through downstream calls so all cancel… request-scoped context propagation.
Logging middleware wrapping an http.Handler in Go
Middleware has signature func(http.Handler) http.Handler, records start time, calls next.ServeHTTP, then logs method, URL, and elapsed duration; chaining works because the wrapper is itself a… the http.Handler middleware pattern.
In-memory rate limiter middleware in Go
Use a token-bucket limiter (golang.org/x/time/rate), guard a per-client map with sync.Mutex, wrap http.Handler so requests over the limit get 429. rate limiting and middleware design.
Structuring a Go CLI that fetches a URL
Parse args with the flag package, http.Get the URL, check err and status, defer resp.Body.Close, copy body to stdout, exit non-zero on failure. basic Go CLI, HTTP, and error handling.
cgo directives: CFLAGS, LDFLAGS, and pkg-config
#cgo CFLAGS feeds the C compiler include paths/defines, LDFLAGS feeds the linker libraries/paths, pkg-config auto-discovers both; needed to compile against a system C library. cgo build configuration.
Passing Go/Rust callbacks to a C library
C needs a plain function pointer; in Go use //export with cgo, in Rust an extern "C" fn; carry state via a void* user-data param. FFI callback mechanics.
Zero-copy string to []byte conversion via unsafe in Go
Use unsafe.StringData/Slice (or reflect headers) to alias the string's bytes without copying; assumes shared backing array; risk is mutating an immutable string. Go memory layout and unsafe trade-offs.
Get GO bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.