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

  1. Explain the difference between an immutable reference (`&T`), a mutable reference (`&mut T`), and a `Box<T>` in Rust.
  2. In a Go gRPC server, what is the primary benefit of making RPC handlers non-blocking?
  3. Analyze the following Go code for concurrency-related issues. What is its behavior?
  4. Analyze the following Rust code snippet. Does it have a lifetime-related error?
  5. Besides a `sync.Mutex`, what is another common and often more performant way to handle a simple shared numeric counter in Go?
  6. How should you handle errors returned by database operations within a Go web service to ensure graceful degradation and avoid crashing the entire service?
  7. A query filtering on two columns (`country` and `city`) is slow. Which indexing strategy would likely provide the best performance improvement?
  8. Analyze the following Go code. Is the error handling and resource management approach correct?
  9. After a `recover` successfully handles a panic inside a function `doWork()`, where does execution control return to?
  10. In a Go `select` statement, which of these cases will prevent the statement from blocking?
  11. The following code attempts to asynchronously read from a TCP socket. It compiles, but it follows an unidiomatic pattern regarding ownership. Identify the issue.
  12. In this TCP server code, a single client disconnecting with an error will shut down the entire server. How can this bug be fixed?
  13. 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?
  14. Review the following code. What potential concurrency issue does it demonstrate?
  15. The following Actix Web code snippet has a potential issue related to error handling best practices in a production environment. Identify the problem.
  16. The following Actix Web code snippet attempts to create a shared counter, but it has a subtle performance bug. Identify the problem.
  17. The following build script fails to correctly write the file. What is the error?
  18. The following `build.rs` script appears to have a concurrency issue. What is the reality of the situation?
  19. A developer wrote this `select` statement inside a loop, intending to time out after 1 second. What is the bug in this code?
  20. Identify the bug in the following Go function. It should handle different types and return an error if the type is not supported.
  21. 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?
  22. Compare and contrast Rust's lifetime-based memory management with automatic garbage collection (GC) found in languages like Java or Go.
  23. Describe a scenario where using interior mutability in Rust is necessary, and explain how you would implement it safely in a multi-threaded context.
  24. Describe performance optimization strategies specifically for a gRPC client in Go.
  25. Describe how you would implement token-based authentication and authorization in a gRPC service built with Go.
  26. Compare and contrast using Redis Lists versus Redis Sorted Sets for implementing a leaderboard feature. Discuss the performance implications of each choice.
  27. Compare and contrast Rust's `HashMap` and `BTreeMap`. In what scenarios would you choose one over the other?
  28. Can a `break` from a labeled loop return a value? If so, explain how and provide a code example.
  29. 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.
  30. Compare and contrast using a custom error enum versus `Box<dyn std::error::Error>` for error handling in a Rust application.
  31. Describe how to prevent deadlocks when using multiple `Mutex`es in Rust. What is the most common strategy?
  32. Describe best practices for designing and using generics in Go to maximize code reusability while minimizing performance overhead.
  33. Compare strategies for optimizing Docker image size for Go and Rust microservices. What techniques are similar and what are the key differences?
  34. Compare and contrast the typical process and challenges of creating a fully static binary in Go versus Rust.
  35. 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?
  36. Beyond the overall percentage, how can you use Go's coverage visualization tools to improve your test suite?
  37. Describe how Go's Minimal Version Selection (MVS) algorithm works and how it differs from dependency resolution in other package managers.
  38. Describe and implement a simple fan-out, fan-in concurrency pattern in Go for parallelizing a CPU-bound task.
  39. Compare and contrast the suitability of a document database (like MongoDB) versus a wide-column store (like Cassandra) for a time-series analytics application.
  40. Describe how to safely share mutable data between multiple threads in Rust. Explain the tradeoffs involved in different approaches.
  41. Describe how to use pointers with arrays and slices in Go. What are the key differences in behavior?
  42. Compare the architectural principles of Actix Web with another popular Rust web framework, Axum.
  43. Beyond 3NF, what is Boyce-Codd Normal Form (BCNF)? Explain what kind of anomaly it solves and provide an example.
  44. Compare and contrast the ACID and BASE transaction models. In what kind of systems is each model typically preferred?
  45. 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?
  46. Compare and contrast `Mutex<T>` and `RwLock<T>` in Rust. Discuss their trade-offs in terms of performance and use cases.
  47. Besides `String`, what is another way to have an owned string slice in Rust, and why might you choose it?
  48. Describe how the Rust compiler transforms an `async fn` into a `Future`. What is the role of the state machine?
  49. 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.
  50. Compare and contrast static and dynamic dispatch in Rust, explaining how each is achieved and their respective performance trade-offs.