complete list of Go (Golang) interview questions
๐งฉ 1. Basic Go Interview Questions
๐น Language Basics
- What are the main features of Go?
- Why was Go developed, and what problems does it solve?
- What are the advantages of using Go over Java, Python, or .NET?
- Explain how Go handles memory management.
- What is a package in Go?
- How do you import packages in Go?
- What is the purpose of the
mainpackage? - What is the difference between
var,:=, andconst? - What are Go data types?
- What are slices in Go? How are they different from arrays?
- How is string handling done in Go?
- What are maps in Go? How do you iterate through a map?
- What are structs?
- What is an interface in Go?
- What is the difference between value type and reference type in Go?
⚙️ 2. Functions and Methods
- How do you define a function in Go?
- What are variadic functions?
- Can functions return multiple values in Go?
- What is a method receiver? Explain value vs pointer receivers.
- Can you assign functions to variables in Go?
- What are closures in Go?
- What are higher-order functions?
- How can you handle errors in Go functions?
- What is
deferused for? - What happens if multiple
deferstatements are used?
๐งต 3. Concurrency in Go (Important for Backend/Microservices)
- What is a goroutine?
- How is concurrency implemented in Go?
- How do you start a goroutine?
- What are channels in Go?
- Difference between buffered and unbuffered channels?
- How to prevent goroutine leaks?
- What is the
selectstatement used for? - What is the difference between concurrency and parallelism?
- How to synchronize goroutines?
- Explain
sync.WaitGroupandsync.Mutex. - What are race conditions? How do you avoid them?
- What is the purpose of
contextin Go? - How can you cancel a long-running goroutine using context?
- Explain fan-in and fan-out patterns.
- How would you implement a worker pool in Go?
๐งฑ 4. Error Handling
- How does Go handle errors (since there are no exceptions)?
- What is the
errorinterface? - How can you create custom error types?
- How do you wrap and unwrap errors in Go 1.13+?
- Difference between
panic,recover, anddefer.
๐งฐ 5. Structs, Interfaces, and OOP Concepts
- What is a struct in Go?
- Can structs have methods?
- How are interfaces different from structs?
- What is interface embedding?
- How do you check if a type implements an interface?
- Can interfaces be empty? What is the use of
interface{}? - How does Go achieve polymorphism?
- What is dependency injection in Go?
- Can Go support inheritance? If not, how do you achieve reuse?
๐ 6. Go Modules and Packages
- What is a Go module?
- How do you initialize a module?
- What is
go.modandgo.sum? - How do you manage dependencies in Go?
- What are the steps to build and run a Go module?
- Difference between
go install,go build, andgo run.
๐️ 7. Go in Microservices and Backend Development
- Why is Go popular for microservices?
- How do you build a REST API in Go?
- What are some popular Go frameworks for web development (e.g., Gin, Echo, Fiber)?
- How do you handle JSON serialization/deserialization in Go?
- How do you connect to databases in Go?
- How do you handle configuration in Go microservices?
- How do you use environment variables in Go?
- How to handle logging and structured logs?
- How to write unit tests in Go (
testingpackage)? - How do you mock dependencies in Go tests?
- How do you containerize a Go application with Docker?
- How do you deploy Go microservices in Kubernetes?
๐งช 8. Testing and Benchmarking
- How do you write test cases in Go?
- How do you run tests using
go test? - How do you write benchmark tests?
- What is table-driven testing?
- How do you use mock interfaces in tests?
⚡ 9. Advanced Go Concepts
- What is reflection in Go? When would you use it?
- How do you use
unsafepackage? - What is
iotain Go? - Explain type embedding.
- How are generics handled in Go (1.18+)?
- What are contexts and how are they used in microservices?
- How does garbage collection work in Go?
- What are Go routines scheduler and GOMAXPROCS?
๐ง๐ป 10. Scenario-Based Questions
- How would you design a concurrent downloader in Go?
- How would you implement a producer-consumer pattern?
- How do you prevent data races in concurrent Go code?
- How would you implement retry logic for failed API calls?
- How to gracefully shut down a Go web server?
- How to limit the number of concurrent goroutines?
- How would you implement rate limiting in Go?
๐ง 11. Practical Code Questions
- Write a Go function to reverse a string.
- Write a Go function to check if a number is prime.
- Implement a worker pool using goroutines and channels.
- Implement a REST API endpoint with JSON response.
- Parse JSON into struct and print specific fields.
- Demonstrate use of
sync.WaitGroup. - Implement retry logic using exponential backoff.
- Create custom error type and handle it graceful
Comments
Post a Comment