Level: AdvancedInterview

Go Concurrency Scenario Questions: Real Cases

Updated 11 min read
Go Concurrency Scenario Questions featured image: leak, race and shutdown cards

These Go concurrency scenario questions describe real problems with goroutines, channels, locks and cancellation, and ask what you would do. Each one comes from the kind of bug that shows up in production, not in a textbook. We gathered them from public interview lists and incident stories, then rewrote each one in our own words.

This post is questions only, so answer each one in your own words first. When you need help, read our post on goroutines, our post on channels and our post on concurrency patterns. Also, finish our post on coding scenarios first, because many of these tasks start as plain code.

How to Use These Go Concurrency Scenario Questions

Read each of these Go concurrency scenario questions, then say what you would check, what you would change and how you would prove it. That three step answer works well in interviews. Finally, run the code examples with -race, since races hide in normal runs.

The table below lists each section and its number of questions.

SectionWhat it testsQuestions
Goroutine lifecycleStart, wait and exit15
Channels and selectBlock, close and timeout15
Shared stateRaces, locks and atomics15
Pools and limitsWorkers, semaphores and rate limits15
Cancel and shutdownContext, signals and draining15
DebuggingStuck, slow and leaking code15
Go Concurrency Scenario Questions diagram showing six kinds of real concurrency problems
The six kinds of concurrency problems covered in this question list.

Go Concurrency Scenario Questions on Goroutine Lifecycle

Before you answer, study Go goroutines for beginners. These Go concurrency scenario questions check that every goroutine you start can finish.

  1. Your CLI prints only part of its output because main exits early, so how would you wait for the workers?
  2. A handler starts a goroutine to send an email, then the email never arrives, so what would you check?
  3. When a service starts one goroutine per request, memory grows during a sale, so what would you change?
  4. A background job panics and takes down the whole API, so how would you contain it?
  5. Imagine a goroutine that runs a loop forever with no exit path, then how would you add one?
  6. Your test passes alone but leaves goroutines running after it ends, so how would you detect that?
  7. After a deploy, the goroutine count climbs by ten thousand an hour, so where would you start?
  8. A teammate uses time.Sleep to wait for goroutines in tests, so what would you suggest?
  9. When you must start exactly one background refresher per process, how would you guarantee it?
  10. A library starts goroutines inside init, so why could that surprise its users?
  11. Your batch job needs a result from each of 50 goroutines, so how would you collect them?
  12. During shutdown, some goroutines are still writing files, so how would you let them finish?
  13. When a goroutine closes over a loop variable in old code, how would you spot the bug?
  14. Scenario: when pprof shows thousands of goroutines in the same stack, how would you find their owner?
  15. Scenario: when a library you call starts goroutines you cannot stop, how would you protect your service?

Go Concurrency Scenario Questions on Channels and select

Before you answer, study Go channels and Go select statement. Most channel bugs end in a hang or a panic, so these Go concurrency scenario questions focus on both.

  1. Your program stops with all goroutines are asleep after a refactor, so how would you find the stuck channel?
  2. A producer panics with send on closed channel during shutdown, so how would you fix the order?
  3. When a consumer loops forever after the channel closes, what did it forget to check?
  4. A results channel fills up and workers block, so how would you size it or drain it?
  5. Imagine two producers writing to one channel, then who should close it, and how?
  6. Your select loop burns CPU at 100 percent, so what might the default case be doing?
  7. After adding a timeout, a goroutine still leaks on every call, so how would you fix the send?
  8. A ticker loop keeps running after the job stops, so what would you add?
  9. When one channel closes early in a merge, how do you keep reading the other one?
  10. A pub-sub system must not slow down when one subscriber is slow, so how would you design it?
  11. Your request must wait for the first of three replies, so how would you write it with select?
  12. When a pipeline stage must stop all earlier stages, how would you signal it?
  13. A teammate uses a buffer of 10000 to fix a deadlock, so what would you ask?
  14. Scenario: when a channel based queue loses messages on restart, what would you change in the design?
  15. Scenario: when a select gives one case far more turns than another, how would you add priority?

Go Concurrency Scenario Questions on Shared State

Before you answer, study Go WaitGroup and Mutex and Go race detector. Shared state causes the hardest bugs, so these Go concurrency scenario questions test your care.

  1. Your service crashes with concurrent map writes once a week, so how would you find and fix it?
  2. A counter shows the wrong total under load but looks fine in tests, so what would you suspect?
  3. When the race detector flags a logging helper, how would you fix it without a global lock?
  4. A cache uses one Mutex and becomes the slowest part of the service, so what would you try?
  5. Imagine a config value that changes at run time and many readers use it, then how would you store it?
  6. Your struct holds a Mutex and someone copies it by value, so what breaks?
  7. After adding an RWMutex, latency gets worse, so why might that happen?
  8. A teammate reads a bool flag from another goroutine without sync, so is it safe?
  9. When two functions take the same two locks in different orders, what can happen?
  10. A slice is appended to from many goroutines, so how would you make it safe?
  11. Your rate counter uses atomic adds but the check and update must happen together, so what would you do?
  12. When a map is read by many goroutines and written once at startup, do you need a lock?
  13. A callback runs while you hold a lock and calls back into your type, so what is the risk?
  14. Scenario: when a race only appears on the 64 core production machines, how would you reproduce it?
  15. Scenario: when a reviewer asks you to prove your type is safe for concurrent use, what tests would you write?

Go Concurrency Scenario Questions on Worker Pools

Before you answer, study Go worker pool pattern and Go rate limiting. These Go concurrency scenario questions check how you keep work fast without overloading anything.

  1. Your import job opens 5000 database connections at once and fails, so how would you limit it?
  2. A partner API allows 20 calls per second, so how would you respect that from many goroutines?
  3. When a worker pool is slower with 64 workers than with 8, what would you check?
  4. A job must process one million rows but keep memory flat, so how would you size the pool?
  5. Imagine results must come back in the same order as the input, then how would you change the pool?
  6. Your crawler must fetch at most four pages per domain at a time, so how would you track limits?
  7. After a worker fails, the whole batch hangs, so what did the pool miss?
  8. A team wants to add workers at run time when the queue grows, so is that worth it?
  9. When CPU-bound work runs in a container with two CPUs, how many workers make sense?
  10. Your pool must retry failed jobs three times without blocking the others, so how would you design it?
  11. A slow job holds a worker for minutes, so how would you add a per-job timeout?
  12. When a queue grows faster than workers can drain it, what options do you have?
  13. Two services share one rate limit, so where should the limiter live?
  14. Scenario: when a nightly batch suddenly takes four times longer, how would you find the bottleneck?
  15. Scenario: when a burst of jobs overloads a downstream service, how would you add backpressure?

Go Concurrency Scenario Questions on Cancellation

Before you answer, study Go context for beginners and Go graceful shutdown. Stopping work is as important as starting it, so these Go concurrency scenario questions cover clean exits.

  1. A user closes the browser but the server keeps running a heavy query, so how would you stop it?
  2. Your service takes two minutes to stop on each deploy, so what would you look at first?
  3. When one of five parallel calls fails, how would you cancel the other four?
  4. A background worker ignores ctx.Done and keeps going, so how would you fix its loop?
  5. Imagine an audit log that must be written even after the request is cancelled, then how would you detach it?
  6. Your shutdown closes the database before workers finish, so how would you fix the order?
  7. After SIGTERM, new requests still arrive for a few seconds, so how would you handle them?
  8. A long CPU loop never checks for cancellation, so how often should it check?
  9. When a retry loop runs past the request deadline, what is missing?
  10. A message consumer must finish its current message on shutdown, so how would you write it?
  11. Your tests leave servers running after they finish, so how would you clean them up?
  12. When a timeout fires but the goroutine keeps writing to a channel, what leaks?
  13. A job runner must stop all jobs within 10 seconds, so how would you enforce it?
  14. Scenario: when users see errors only during deploys, how would you change the shutdown steps?
  15. Scenario: when a cancelled request still charges a customer, what would you change in the design?

Debugging Stuck and Slow Concurrent Code

Before you answer, study Go profiling with pprof. These Go concurrency scenario questions finish with the tools you reach for when something is stuck.

  1. A service stops answering but CPU is near zero, so how would you get a goroutine dump?
  2. Your p99 latency spikes while average latency looks fine, so which profile would you take?
  3. When a mutex profile shows long waits on one lock, what would you change?
  4. A block profile points at a channel receive, so what does that tell you?
  5. Imagine a deadlock that happens once a day in production, then how would you gather evidence?
  6. Your goroutine count is stable but memory keeps growing, so where would you look?
  7. After moving to Go 1.25, CPU use drops in containers, so what changed?
  8. A trace shows goroutines waiting for a P, so what does that mean?
  9. When a test fails one run in fifty, how would you make it fail every time?
  10. A worker hangs on a network call with no timeout, so how would you find and fix it?
  11. Your team wants to log every goroutine start and stop, so is that a good idea?
  12. When a hang only happens under heavy load, how would you reproduce it locally?
  13. A teammate adds sleeps to fix a race, so how would you explain the risk?
  14. Scenario: when an on-call engineer must restart a service every night, how would you find the real cause?
  15. Scenario: when a race fix makes the service 30 percent slower, how would you balance safety and speed?

Code Reading Questions

Read each program carefully and predict the output before you run it. Then explain the result in your own words.

package main

import (
    "fmt"
    "strings"
    "sync"
)

func main() {
    words := []string{"go", "rust", "zig", "java"}
    out := make([]string, len(words))
    var wg sync.WaitGroup
    for i, w := range words {
        wg.Add(1)
        go func() {
            defer wg.Done()
            out[i] = strings.ToUpper(w)
        }()
    }
    wg.Wait()
    fmt.Println(strings.Join(out, ","))

    results := make(chan int, len(words))
    for _, w := range words {
        go func() { results <- len(w) }()
    }
    total := 0
    for range words {
        total += <-results
    }
    fmt.Println("total letters:", total)
}
  1. Why does the first line always keep the input order, even though goroutines finish in any order?
  2. How does the second loop know when it has every result, without a WaitGroup?

The second program races three regions against one shared deadline.

package main

import (
    "context"
    "fmt"
    "time"
)

func fetch(ctx context.Context, name string, d time.Duration) (string, error) {
    select {
    case <-time.After(d):
        return name, nil
    case <-ctx.Done():
        return "", ctx.Err()
    }
}

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 80*time.Millisecond)
    defer cancel()
    ch := make(chan string, 3)
    regions := map[string]time.Duration{"eu": 30 * time.Millisecond, "us": 60 * time.Millisecond, "asia": 200 * time.Millisecond}
    for name, d := range regions {
        go func() {
            v, err := fetch(ctx, name, d)
            if err != nil {
                v = name + ": " + err.Error()
            }
            ch <- v
        }()
    }
    for range 3 {
        fmt.Println(<-ch)
    }
}
  1. In what order do the three lines print, and why does asia report an error?
  2. Why is the results channel buffered, and what would leak if it were not?

Quick Revision Table for Concurrency Fixes

Use the table below as a final check before your interview. It maps common symptoms to the first fix to try.

SymptomLikely causeFirst fix
Program hangs, CPU idleDeadlock or stuck channelGoroutine dump, check senders
Goroutines keep growingLeak on send or receiveBuffer, done channel or context
Wrong totals under loadData raceRun -race, add sync
Panic on concurrent map writesUnsafe shared mapMutex or sharding
Slow under load, CPU idleLock or channel waitsMutex and block profiles
Slow shutdownWorkers ignore cancelCheck ctx.Done in loops

Also, many interviewers ask when to use a channel and when to use a lock. The diagram below shows the difference side by side.

Go concurrency scenario diagram comparing a channel with a mutex
A channel passes data and ownership between goroutines, while a mutex guards data that many goroutines share.

Official Resources

These official pages explain the rules behind these scenarios.

Quick Recap

  • These Go concurrency scenario questions cover lifecycle, channels, shared state, pools, shutdown and debugging.
  • Every goroutine needs an owner and a clear way to exit.
  • Only the sender closes a channel, and buffered results channels prevent many leaks.
  • Run -race in CI, and protect shared maps and counters.
  • Limit concurrency with pools, semaphores and rate limiters.
  • Use goroutine dumps and pprof profiles to find stuck or slow code.

What’s Next?

By now, you have Go concurrency scenario questions for the problems that real services hit. Practise your answers out loud, then check your progress in the Go interview topics study guide.

Next up: Go API design scenario questions