Go Developer interview question

How do you profile a Go service?

Profile before optimising. Use pprof to compare CPU, heap, goroutine, mutex, or block profiles against a baseline, then validate the change with the same workload.

Direct answer

What a strong answer covers

How it works

Profiling answers where time and memory actually go instead of where they are assumed to go. pprof collects CPU samples, heap allocations, blocking, mutex contention, and goroutine snapshots; each profile answers a different question, so the symptom decides which one to capture. A useful profile comes from realistic load, is compared against a baseline, and is followed by a benchmark that proves the fix rather than a second guess.

Example

Expose protected pprof endpoints, capture a CPU profile under representative load, and inspect the hottest call path before changing allocations. When an API showed high GC pressure, the heap profile pointed at per-request JSON buffers; reusing a sync.Pool cut allocations by a third, verified with go test -bench and -benchmem before and after.

Common mistakes

  • Optimising code the profile never showed as hot.
  • Profiling an idle process and concluding that the service is fine.
  • Leaving pprof exposed without authentication on a public listener.

A useful answer structure

Answer from your own work.

Do not memorise a script: use only examples you can explain honestly in follow-up questions.

Practise this answer with MiraHint

Open the desktop workspace and rehearse a clear answer in your own words.

Download MiraHint
Go Developer interview questions