Go

The language you reach for when a service has to be small, fast to start and boring to operate.

1guide Feed

Go is what CodeNx reaches for when a service has to start fast, hold a predictable amount of memory and be operable by somebody who did not write it. The language is deliberately small, the toolchain is one binary, and the output is one more binary with no runtime to install alongside it.

Reach for Go when the workload is concurrent I/O — a proxy, a webhook receiver, an import worker, a CLI shipped to other people’s machines — or when the deployment target rewards a small static binary. Reach for something else when the library you need only exists in npm or PyPI, or when the team writes TypeScript all day and the service is not on a hot path; a language nobody on call reads is a liability regardless of its benchmark numbers.

Version policy first. A major release lands every February and August, and each one is supported until two newer majors exist — so the supported set is always the latest two. Record the version in go.mod with the go and toolchain directives, which makes the build reproducible independent of the image tag. The Go 1 compatibility promise means these upgrades are usually uneventful; where they cannot be, the old behaviour stays available through GODEBUG.

The production behaviour that catches people is lifetime, not syntax. A goroutine that blocks forever is a leak the garbage collector cannot help with, so every one of them needs a context that is eventually cancelled. http.Server has no default timeouts at all, which means a client that opens a connection and sends nothing keeps it. database/sql has no default connection cap, so the first real traffic spike is felt by the database rather than the service. And the garbage collector sizes the heap by a growth ratio, so a container memory limit it does not know about is enforced by the OOM killer instead — GOMEMLIMIT is how you tell it.

CodeNx does not have standalone Go articles yet. This hub maps the topic and links the primary sources until it does.

Common problems

Failure modes that come up repeatedly with Go, and where each one is solved.

A goroutine outlives the request that started it
A goroutine blocked on a channel nobody reads, or on a call with no context deadline, is never collected. Pass a cancellable context down and make every blocking path select on `ctx.Done()`.
The HTTP server has no timeouts
`http.Server` ships with none. A slow or idle client holds a connection open indefinitely until the process runs out of them. Set `ReadHeaderTimeout`, `ReadTimeout`, `WriteTimeout` and `IdleTimeout`.
The database connection pool exhausts the database
`database/sql` opens unlimited connections by default, so a traffic spike opens more than the server accepts. Set `SetMaxOpenConns` below the database limit divided by the number of replicas.
The container is OOM-killed while the heap looks fine
The garbage collector targets a growth ratio, not the cgroup limit. Set `GOMEMLIMIT` a little under the container memory limit so collection is triggered by the ceiling that actually kills the process.

Latest Go guides

Browse the archive

Frequently asked questions

Which Go version should a production service run?

One of the two most recent major releases. Go ships a major release every February and August, and the team supports each one until two newer majors exist, so staying one behind is fine and two behind is unsupported. Pin it with the `go` and `toolchain` lines in `go.mod` rather than whatever the build image happens to have.

Do Go upgrades break code?

Rarely, by design. The Go 1 compatibility promise means programs that build today are meant to keep building on later Go 1 releases. Behaviour changes that cannot be avoided go behind GODEBUG settings, which is worth knowing about before blaming your own code for a post-upgrade regression.

Does Go respect a container CPU limit?

Since Go 1.25 the runtime takes the cgroup CPU bandwidth limit into account when defaulting `GOMAXPROCS`. On older releases it counts host CPUs instead, which over-schedules a limited container, and the usual fix is `go.uber.org/automaxprocs` or setting `GOMAXPROCS` explicitly.

Why is a Go container image so much smaller than a Node one?

The build produces one statically linked binary, so the runtime image can be `scratch` or distroless with no interpreter, no module tree and no package manager. Build in a full image, copy the binary into an empty one.

Sources

  1. Go documentation Google Primary source
  2. Go release history Google Primary source
  3. Go 1 and the future of Go programs Google Primary source