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.”

In plain English The GC is constantly balancing two costs: memory growth and CPU work. If you allow more memory growth, the runtime can collect less often. If you demand tighter memory, the runtime must work harder to keep up.

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.

The mental model 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

Backend use case Many services in a monorepo end up running in containers with finite memory budgets. If traffic spikes create temporary heap bursts, 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.
Common mistake Tuning GC from folklore. If you cannot say whether your real issue is memory growth, GC CPU burn, or tail-latency instability, you do not yet know what to tune.
Read this next

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.

go.dev/doc/gc-guide
pkg.go.dev/runtime

Check yourself (from memory)

Q1. Raising GOGC usually means…

Higher GOGC usually trades more memory for less frequent GC work.

Q2. GOMEMLIMIT is best described as…

It guides the runtime; it is not the same thing as an OS or cgroup enforcement limit.
What is the senior answer to “Should we tune the GC?”
recall, then click to reveal
Only after measurement shows a real memory, CPU, or latency problem — then explain which trade-off you want GOGC or GOMEMLIMIT to shift.
Want a concrete “2GiB container, bursty traffic, now what?” walkthrough? Ask me.

Sources. A Guide to the Go Garbage Collector; runtime package docs.