Top Go & Rust Interview Questions
Top 50 Go & Rust interview questions with curated answers across core concepts, practical scenarios, and interview-ready fundamentals.
Top 50 Go & Rust Interview Questions
- Explain the difference between an immutable reference (`&T`), a mutable reference (`&mut T`), and a `Box<T>` in Rust.
- In a Go gRPC server, what is the primary benefit of making RPC handlers non-blocking?
- Analyze the following Go code for concurrency-related issues. What is its behavior?
- Analyze the following Rust code snippet. Does it have a lifetime-related error?
- Besides a `sync.Mutex`, what is another common and often more performant way to handle a simple shared numeric counter in Go?
- How should you handle errors returned by database operations within a Go web service to ensure graceful degradation and avoid crashing the entire service?
- A query filtering on two columns (`country` and `city`) is slow. Which indexing strategy would likely provide the best performance improvement?
- Analyze the following Go code. Is the error handling and resource management approach correct?
- After a `recover` successfully handles a panic inside a function `doWork()`, where does execution control return to?
- In a Go `select` statement, which of these cases will prevent the statement from blocking?
- The following code attempts to asynchronously read from a TCP socket. It compiles, but it follows an unidiomatic pattern regarding ownership. Identify the issue.
- In this TCP server code, a single client disconnecting with an error will shut down the entire server. How can this bug be fixed?
- A project has an indirect dependency on a library version with a known security vulnerability. How can you force the build to use a patched version?
- Review the following code. What potential concurrency issue does it demonstrate?
- The following Actix Web code snippet has a potential issue related to error handling best practices in a production environment. Identify the problem.
- The following Actix Web code snippet attempts to create a shared counter, but it has a subtle performance bug. Identify the problem.
- The following build script fails to correctly write the file. What is the error?
- The following `build.rs` script appears to have a concurrency issue. What is the reality of the situation?
- A developer wrote this `select` statement inside a loop, intending to time out after 1 second. What is the bug in this code?
- Identify the bug in the following Go function. It should handle different types and return an error if the type is not supported.
- Compare and contrast the `read_exact`, `read_until`, and `read_to_end` methods from `AsyncReadExt`. In what scenarios would you choose one over the others?
- Compare and contrast Rust's lifetime-based memory management with automatic garbage collection (GC) found in languages like Java or Go.
- Describe a scenario where using interior mutability in Rust is necessary, and explain how you would implement it safely in a multi-threaded context.
- Describe performance optimization strategies specifically for a gRPC client in Go.
- Describe how you would implement token-based authentication and authorization in a gRPC service built with Go.
- Compare and contrast using Redis Lists versus Redis Sorted Sets for implementing a leaderboard feature. Discuss the performance implications of each choice.
- Compare and contrast Rust's `HashMap` and `BTreeMap`. In what scenarios would you choose one over the other?
- Can a `break` from a labeled loop return a value? If so, explain how and provide a code example.
- Can a Go `switch` statement's cases overlap in a tagless switch (e.g., `case x > 10` and `case x > 5`)? Explain how Go evaluates and executes such cases.
- Compare and contrast using a custom error enum versus `Box<dyn std::error::Error>` for error handling in a Rust application.
- Describe how to prevent deadlocks when using multiple `Mutex`es in Rust. What is the most common strategy?
- Describe best practices for designing and using generics in Go to maximize code reusability while minimizing performance overhead.
- Compare strategies for optimizing Docker image size for Go and Rust microservices. What techniques are similar and what are the key differences?
- Compare and contrast the typical process and challenges of creating a fully static binary in Go versus Rust.
- Compare and contrast Go's built-in `testing` package with a popular third-party assertion library like `testify/assert`. What are the pros and cons of each approach?
- Beyond the overall percentage, how can you use Go's coverage visualization tools to improve your test suite?
- Describe how Go's Minimal Version Selection (MVS) algorithm works and how it differs from dependency resolution in other package managers.
- Describe and implement a simple fan-out, fan-in concurrency pattern in Go for parallelizing a CPU-bound task.
- Compare and contrast the suitability of a document database (like MongoDB) versus a wide-column store (like Cassandra) for a time-series analytics application.
- Describe how to safely share mutable data between multiple threads in Rust. Explain the tradeoffs involved in different approaches.
- Describe how to use pointers with arrays and slices in Go. What are the key differences in behavior?
- Compare the architectural principles of Actix Web with another popular Rust web framework, Axum.
- Beyond 3NF, what is Boyce-Codd Normal Form (BCNF)? Explain what kind of anomaly it solves and provide an example.
- Compare and contrast the ACID and BASE transaction models. In what kind of systems is each model typically preferred?
- Besides the standard `serde_json` crate, what other types of JSON libraries exist in the Rust ecosystem for high-performance use cases, and what is their underlying principle?
- Compare and contrast `Mutex<T>` and `RwLock<T>` in Rust. Discuss their trade-offs in terms of performance and use cases.
- Besides `String`, what is another way to have an owned string slice in Rust, and why might you choose it?
- Describe how the Rust compiler transforms an `async fn` into a `Future`. What is the role of the state machine?
- Can a single `defer` block contain a `recover` that handles multiple different types of panics (e.g., `panic("a string")` vs. `panic(MyError{})`)? Explain how you would handle this.
- Compare and contrast static and dynamic dispatch in Rust, explaining how each is achieved and their respective performance trade-offs.