Lesson 25 · Senior Go backend engineering
GC tuning: GOGC & GOMEMLIMIT
How senior engineers talk about memory budgets, latency, and the garbage collector.
Your win: explain what Go's garbage collector is optimising for, what GOGC and GOMEMLIMIT actually change, and why the senior answer is almost always “measure first, then tune with a clear trade-off in mind.”
What the GC is trying to do
Go's collector is designed around low pause times, not around “never use CPU.” That is why good GC explanations sound like trade-offs, not absolutes. A senior engineer should be able to say what is being traded: memory headroom for CPU time, and often both for latency stability.
GOGC changes how much the heap may grow before the runtime feels more pressure to collect. GOMEMLIMIT gives the runtime a soft memory budget to respect when memory is genuinely constrained.
The two knobs that matter most
GOGC
Higher usually means more heap growth and less frequent GC. Lower usually means less heap growth and more GC work.
GOMEMLIMIT
A soft memory budget, especially useful in containers and other memory-constrained environments.
What to say in an interview
- Go's GC is concurrent and tuned for low pauses.
GOGCis a space-versus-CPU trade-off knob.GOMEMLIMITmatters when the deployment has a real memory ceiling.- The adult answer is not “always set it to X.” It is “profile the workload, then tune for the problem you actually have.”
GOMEMLIMIT can be the difference between a stable service and an OOM-killed one. That is why senior backend engineers care about it even if they never write runtime code directly.
The official GC guide
This is the best high-trust source for how the collector behaves and how its main knobs trade space for time.
Check yourself (from memory)
Q1. Raising GOGC usually means…
GOGC usually trades more memory for less frequent GC work.Q2. GOMEMLIMIT is best described as…
GOGC or GOMEMLIMIT to shift.Sources. A Guide to the Go Garbage Collector; runtime package docs.