How to approach scenario questions
Interviewers want to hear how you investigate constraints, make trade-offs, and verify a solution. Use each problem to explain a practical decision process, not just name a language feature.
A clear answer structure
- Clarify requirements and failure conditions.
- Explain the approach and why it fits.
- Cover trade-offs, safety, and edge cases.
- Describe how you would test and measure it.
Real-world problem 1
An HTTP handler keeps running after the client disconnects. What should you change?
The scenario
The handler starts database and downstream calls that continue consuming resources after the incoming request has been canceled.
A strong answer
Propagate r.Context() to database queries and downstream requests, and check cancellation in long-running work. Set appropriate server and client timeouts. Do not replace the request context with context.Background() for work that should end with the request.
Real-world problem 2
A service leaks goroutines under load. How would you find and prevent the leak?
The scenario
The goroutine count rises over time when a downstream dependency is slow or a consumer exits early.
A strong answer
Capture goroutine profiles and inspect where blocked goroutines are waiting. Give every goroutine a clear owner and exit condition, propagate cancellation, and ensure channel sends can be interrupted when receivers stop. Test shutdown and cancellation paths under load.
Real-world problem 3
A concurrent map occasionally panics or returns inconsistent values. What is the correct fix?
The scenario
Several goroutines read and write a regular map while processing requests.
A strong answer
A built-in map is not safe for concurrent writes. Protect related map operations with a mutex or redesign ownership so one goroutine owns the state and communicates through channels. Run tests with the race detector and choose sync.Map only for suitable access patterns.
Real-world problem 4
An endpoint fans out to hundreds of services and overloads them. How do you bound the work?
The scenario
Each request launches a goroutine per dependency, causing traffic spikes and excessive memory use.
A strong answer
Limit concurrent work with a worker pool or semaphore, and apply request deadlines and cancellation. Set limits based on downstream capacity, not just local CPU count. Record queue depth and latency so overload is visible instead of hidden in an unbounded queue.
Real-world problem 5
How would you shut down a Go HTTP service without dropping in-flight requests?
The scenario
A container receives a termination signal while users are still making requests.
A strong answer
Listen for the termination signal, stop accepting new work, and call Server.Shutdown with a bounded context so active requests can finish. Close background workers and dependencies after draining. Define what happens when the grace period expires and test that path.
Real-world problem 6
A queued job is delivered multiple times and sometimes fails temporarily. How should a worker handle it?
The scenario
The queue provides at-least-once delivery, so a worker can see the same job again after a crash or timeout.
A strong answer
Make job processing idempotent using a stable job ID and durable completion state. Retry only transient failures with capped exponential backoff and jitter, limit attempts, and route exhausted jobs to a dead-letter flow for investigation.
Real-world problem 7
A Go service has high latency and garbage-collection pressure. What is your first step?
The scenario
A rewrite to reduce allocations is proposed, but the team has not identified which code path is responsible.
A strong answer
Capture CPU, heap, allocation, and blocking profiles under a representative workload, then use benchmarks to isolate hot paths. Reduce measured allocations or unnecessary copies and compare results. Avoid pooling or unsafe optimizations until profiling demonstrates a need.
Real-world problem 8
A request depends on several downstream results, but partial results may still be useful. How do you model failures?
The scenario
One downstream call can fail while other calls return valid data for the response.
A strong answer
First define whether the operation is all-or-nothing or permits partial success. Use a cancellation-aware error group when any failure should cancel sibling work. For partial results, collect per-call outcomes and return explicit status for missing sections instead of discarding successful data.