More in Backend Dev — page 16
Rust lifetimes versus Go garbage-collected lifetimes
WHAT IT TESTS: understanding of how Rust tracks reference validity. OUTLINE: 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.
Fearless concurrency: Rust compile-time vs Go runtime
WHAT IT TESTS: understanding of where each language catches concurrency bugs. OUTLINE: 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…
Why Pin is needed for self-referential Futures
WHAT IT TESTS: deep grasp of async internals. OUTLINE: async blocks compile to state machines that can hold references into their own storage; Pin guarantees the value will not move so those internal pointers stay valid across polls.
Architecting an L7 proxy in Go versus Rust
WHAT IT TESTS: ability to weigh systems trade-offs under real constraints. OUTLINE: 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.
Rust Send and Sync marker traits explained
WHAT IT TESTS: understanding of compile-time thread-safety guarantees. OUTLINE: Send means a value can move across threads, Sync means a reference can be shared; Rc uses non-atomic refcounts, Arc uses atomic ones. RED FLAG: confusing the two traits.
Using context.Context across microservice calls in Go
WHAT IT TESTS: request-scoped context propagation. OUTLINE: 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…
Static dispatch over Write with generics in Rust
WHAT IT TESTS: static vs dynamic dispatch trade-offs. OUTLINE: write generically over the std::io::Write trait with a type parameter W: Write, letting the compiler monomorphize and inline per concrete type, avoiding the vtable indirection of Box<dyn Write>.
Logging middleware wrapping an http.Handler in Go
WHAT IT TESTS: the http.Handler middleware pattern. OUTLINE: 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…
In-memory rate limiter middleware in Go
WHAT IT TESTS: rate limiting and middleware design. OUTLINE: 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.
Handling Result and errors in a Rust web handler
WHAT IT TESTS: Result-based error handling in web handlers. OUTLINE: handler returns Result, the ? operator early-returns errors, a custom error type implements IntoResponse to map to 500, success returns 200 with data.
Structuring a Go CLI that fetches a URL
WHAT IT TESTS: basic Go CLI, HTTP, and error handling. OUTLINE: 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.
cgo directives: CFLAGS, LDFLAGS, and pkg-config
WHAT IT TESTS: cgo build configuration. OUTLINE: #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.
Building a safe Rust wrapper over an unsafe C API
WHAT IT TESTS: FFI encapsulation patterns. OUTLINE: hide extern calls behind a safe module, own the resource in a struct with Drop calling the C free, return Result mapping C error codes, use NewType/NonNull and PhantomData.
Passing Go/Rust callbacks to a C library
WHAT IT TESTS: FFI callback mechanics. OUTLINE: 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.
Zero-copy string to []byte conversion via unsafe in Go
WHAT IT TESTS: Go memory layout and unsafe trade-offs. OUTLINE: 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.
Rust references vs raw pointers
WHAT IT TESTS: safety invariants of references. OUTLINE: references are borrow-checked, always valid, aliasing-controlled, non-null; raw pointers carry no guarantees, can be null, dangling, or aliased, and dereferencing needs unsafe.
Profiling a Rust hot loop with perf
WHAT IT TESTS: low-level performance profiling. OUTLINE: build with debuginfo, perf record cycles or cache-misses, perf report then perf annotate to map counters to source/asm; flamegraph for hotspots.
Diagnosing Go memory leaks with pprof heap profiles
WHAT IT TESTS: production profiling with pprof. OUTLINE: expose net/http/pprof, grab /debug/pprof/heap, analyze inuse_space for live retention versus alloc_space for cumulative allocation; rising inuse over time points to a leak.
Cancellation: Go context vs Rust sync stdlib
WHAT IT TESTS: cancellation propagation models. OUTLINE: Go's context.Context threads a Done channel and deadline through call chains; Rust std has no built-in cancellation, so you wire an AtomicBool or channel and check it.
Network read/write timeouts in Go vs Rust stdlib
WHAT IT TESTS: stdlib IO timeout APIs and design philosophy. OUTLINE: Go uses SetReadDeadline/SetWriteDeadline as absolute times; Rust uses set_read_timeout/set_write_timeout as durations on TcpStream.