Level: AdvancedInterview

Go Performance Scenario Questions: Slow Services

Updated 10 min read
Go Performance Scenario Questions featured image: tail latency, allocations and profiling cards

These Go performance scenario questions describe slow services, high memory, GC pauses and latency spikes, then ask how you would fix them. Each one follows the same path a real engineer takes during a performance review. 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 performance, Go profiling with pprof and Go garbage collector and memory. Also, finish our post on testing scenarios first, because benchmarks are tests too.

How to Use These Go Performance Scenario Questions

For each of these Go performance scenario questions, name the profile or metric you would check first. Then say what change you expect to help and how you would prove it with numbers. Finally, mention the risk of the change, since speed fixes can hurt clarity.

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

SectionWhat it testsQuestions
CPU hot pathsLoops, JSON and regex15
Memory and GCAllocations, leaks and limits15
Tail latencyp99, queues and locks15
Database and networkQueries, pools and remote calls15
Containers and scalingCPU limits, memory and replicas15
Proving fixesBenchmarks, profiles and load tests15
Go Performance Scenario Questions diagram showing six kinds of slow service problems
The six kinds of slow service problems covered in this question list.

Go Performance Scenario Questions on CPU Hot Paths

Before you answer, study Go profiling with pprof. These Go performance scenario questions start with code that burns CPU.

  1. A CPU profile shows 40 percent of time in encoding/json, so what options would you consider?
  2. Your handler compiles the same regexp on every request, so what would you change?
  3. When fmt.Sprintf appears high in a profile for a log key, how would you replace it?
  4. A loop converts the same string to bytes on every pass, so how would you avoid the copies?
  5. Imagine a hot function that uses reflection to read struct fields, then how would you speed it up?
  6. Your service hashes passwords on the request path and CPU spikes during logins, so what is normal here?
  7. After a release, CPU doubles but traffic is the same, so how would you compare profiles?
  8. A sort runs on every request over the same data, so what would you cache?
  9. When a map lookup with a string key shows up in a flame graph, how would you check if it matters?
  10. Your gzip middleware uses a lot of CPU, so which settings would you try?
  11. A logger formats debug lines even when debug is off, so how would you fix it?
  12. When interface calls appear hot in a tight loop, how would you test a concrete type instead?
  13. Your team wants to turn on profile-guided optimization, so how would you set it up?
  14. Scenario: when a CPU profile looks flat with no clear hot spot, what would you check next?
  15. Scenario: when a micro-optimisation makes code harder to read for a 2 percent gain, would you merge it?

Go Performance Scenario Questions on Memory and GC

Before you answer, study Go garbage collector and memory. Memory problems often look like CPU problems, so these Go performance scenario questions connect the two.

  1. A service uses 4 GB of memory but heap profiles show 500 MB, so where is the rest?
  2. Your pods get OOM-killed during traffic peaks, so how would you set GOMEMLIMIT?
  3. When GC takes 25 percent of CPU, what would you reduce first?
  4. A cache map grows forever, so how would you bound it?
  5. Imagine a sub-slice of a 10 MB buffer kept in a long-lived struct, then what leaks?
  6. Your handler allocates a new 64 KB buffer per request, so how would sync.Pool help?
  7. After adding sync.Pool, memory use goes up, so what could be wrong?
  8. A goroutine leak shows up as slowly rising memory, so how would you confirm it?
  9. When strings built from large inputs stay alive, how would you copy only what you need?
  10. Your service starts slow because it loads a big file into memory, so what would you change?
  11. A heap profile shows many small allocations from one function, so how would you cut them?
  12. When escape analysis moves a value to the heap, how would you check why?
  13. A team sets GOGC=off to save CPU, so what risk does that bring?
  14. Scenario: when memory climbs only on Mondays, how would you find what is different?
  15. Scenario: when a fix halves allocations but latency does not change, what would you look at next?

Go Performance Scenario Questions on Tail Latency

Before you answer, study our post on the sync package. Users feel the slowest requests, so these Go performance scenario questions focus on p99.

  1. Average latency is 20 ms but p99 is 900 ms, so where would you start?
  2. Your mutex profile shows long waits on one cache lock, so what would you change?
  3. When a worker queue backs up during peaks, how does that show in latency?
  4. A request fans out to ten services and waits for all, so how does tail latency grow?
  5. Imagine sending a backup request after 50 ms to a second replica, then what are the trade-offs?
  6. Your logs flush to disk on the request path, so how could that cause spikes?
  7. After moving to a bigger instance, p99 stays high, so what does that suggest?
  8. A GC pause lines up with latency spikes, so how would you confirm it with a trace?
  9. When one slow customer slows everyone, how would you isolate them?
  10. Your service hits the downstream connection pool limit, so what do requests do?
  11. A cold cache after deploy causes slow minutes, so how would you warm it?
  12. When retries make tail latency worse, how would you limit them?
  13. A load balancer sends uneven traffic to pods, so how would you find hot pods?
  14. Scenario: when p99 spikes every 30 seconds like clockwork, what would you suspect?
  15. Scenario: when a product manager wants p99 under 100 ms, how would you plan the work?

Go Performance Scenario Questions on Databases and Networks

Before you answer, study our post on database scenarios and Go HTTP client. Most backend time goes to waiting on IO, so these Go performance scenario questions focus there.

  1. A trace shows 80 percent of request time waiting on the database, so what would you check?
  2. Your service opens a new HTTP connection for every outgoing call, so what is missing?
  3. When a page makes 50 small queries, how would you batch them?
  4. A JSON API sends 2 MB responses to mobile users, so how would you shrink them?
  5. Imagine three remote calls made one after another, then which ones could run at the same time?
  6. Your DNS lookups are slow inside the cluster, so how would you confirm and fix it?
  7. After enabling TLS between services, CPU rises, so what would you look at?
  8. A gRPC stream sends tiny messages one by one, so how would batching help?
  9. When pool wait time rises in db.Stats, should you raise the pool size or fix queries?
  10. Your service reads a config from a remote store on every request, so what would you cache?
  11. A batch job writes rows one at a time, so how would you speed up inserts?
  12. When a Redis call takes 5 ms on average, how many calls per request is too many?
  13. A health check runs a heavy query every second, so what would you change?
  14. Scenario: when moving the database to another region doubles latency, what design changes would you make?
  15. Scenario: when a partner API is slow and you cannot change it, how would you protect your latency?

Go Performance Scenario Questions on Containers

Before you answer, study our post on deployment. These Go performance scenario questions look at how limits and scaling change performance.

  1. Kubernetes throttles a service because of CPU limits, so how would you spot it?
  2. Your Go version is older than 1.25 in a container with 2 CPUs on a 64 core node, so what goes wrong?
  3. When memory limits are tight, how should GOMEMLIMIT relate to them?
  4. A deployment grows from 3 to 30 pods but throughput barely moves, so what is shared?
  5. Imagine an autoscaler that reacts too slowly to spikes, then what would you tune?
  6. Your pods start slowly and miss readiness, so how would you speed up startup?
  7. After moving to ARM nodes, some benchmarks change, so how would you compare fairly?
  8. A sidecar uses more CPU than your app, so how would you measure the real cost?
  9. When a single pod handles twice the load of others, how would you rebalance?
  10. Your service caches data in memory per pod, so how does scaling out affect hit rate?
  11. A job runs faster on a laptop than in the cluster, so what differences would you check?
  12. When should you scale up instead of out?
  13. How would you size CPU and memory requests for a new service?
  14. Scenario: when the cloud bill doubles but traffic is flat, how would you find the waste?
  15. Scenario: when marketing expects a traffic spike next week, how would you load test and prepare?

Measuring and Proving Fixes

Before you answer, study Go benchmarks. These Go performance scenario questions finish with proof, because a fix without numbers is only a guess.

  1. A teammate claims a change is 30 percent faster, so what evidence would you ask for?
  2. Your benchmark results vary by 15 percent between runs, so how would you make them stable?
  3. When a micro-benchmark improves but the service does not, what might be missing?
  4. A load test must mimic real traffic, so where would you get the request mix?
  5. Imagine a performance budget for each endpoint, then how would CI enforce it?
  6. Your team wants continuous profiling in production, so what would it give you?
  7. After a fix, how long would you watch production metrics before calling it done?
  8. A benchmark shows fewer allocations but more CPU, so how would you decide?
  9. When comparing two Go versions, how would you run a fair test?
  10. Your dashboard shows only averages, so which metrics would you add?
  11. A regression slipped in three weeks ago, so how would you find the commit?
  12. When should you stop optimising and move on?
  13. How would you write up a performance fix for the team?
  14. Scenario: when a fix helps in staging but hurts in production, what differences would you check?
  15. Scenario: when leadership asks how fast the service can get, how would you answer with data?

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"
    "strconv"
    "strings"
    "testing"
)

var sink string

func plus(n int) string {
    s := ""
    for i := range n {
        s += strconv.Itoa(i)
    }
    return s
}

func builder(n int) string {
    var b strings.Builder
    b.Grow(n * 3)
    for i := range n {
        b.WriteString(strconv.Itoa(i))
    }
    return b.String()
}

func main() {
    a := testing.AllocsPerRun(50, func() { sink = plus(200) })
    b := testing.AllocsPerRun(50, func() { sink = builder(200) })
    fmt.Println(a, b)
    fmt.Println(len(plus(200)) == len(builder(200)))
}
  1. Why does plus allocate far more than builder, and where do most of its allocations come from?
  2. Why does builder still allocate about 100 times, and how would strconv.AppendInt remove them?

The second program counts how often a slice grows.

package main

import "fmt"

func main() {
    var s []int
    grows := 0
    lastCap := cap(s)
    for i := range 1000 {
        s = append(s, i)
        if cap(s) != lastCap {
            grows++
            lastCap = cap(s)
        }
    }
    fmt.Println(len(s), grows)
    t := make([]int, 0, 1000)
    before := cap(t)
    for i := range 1000 {
        t = append(t, i)
    }
    fmt.Println(cap(t) == before)
}
  1. How many times does s grow, and what does each growth cost?
  2. Why does t never grow, and when is preallocating not possible?

Quick Revision Table for Performance Fixes

Use the table below as a final check before your interview. It maps common symptoms to the tool and the usual fix.

SymptomTool to useUsual fix
High CPUCPU profileCache, avoid reflection, compile once
High memoryHeap profileBound caches, copy small slices
GC eats CPUgctrace, heap profileFewer allocations, GOMEMLIMIT
High p99Trace, mutex profileShorter locks, fewer queues
Slow IOTraces, db.StatsBatch, reuse connections
Throttled podsContainer metricsRight limits, Go 1.25 GOMAXPROCS

Also, many interviewers ask you to explain throughput and latency. The diagram below shows the difference side by side.

Go performance scenario diagram comparing throughput and latency
Throughput measures how much work a service does per second, while latency measures how long each request waits.

Official Resources

These official pages explain the tools behind these scenarios.

Quick Recap

  • These Go performance scenario questions cover CPU, memory, tail latency, IO, containers and proof.
  • Profile first, then fix the hot path that the numbers point to.
  • Fewer allocations help both memory and GC time.
  • Watch p99, not only averages, because users feel the slow tail.
  • Most backend time is IO, so batch calls and reuse connections.
  • Prove every fix with benchmarks, load tests and production metrics.

What’s Next?

By now, you have Go performance scenario questions for the slow service problems teams face. Practise your answers out loud, then check your progress in the Go interview topics study guide.

Next up: Go production debugging scenarios