Cloud & Serverless Best Practices
Cold start tuning, observability, and cost guardrails.
Search across all documentation pages
Cold start tuning, observability, and cost guardrails.
Apply these rules in CI templates, service README files, and platform reviews so every Go deployment gets predictable latency, bills, and incident response.
CGO_ENABLED=0 for Lambda and minimal containers. Avoids dynamic linker surprises on provided runtimes.-ldflags="-s -w" unless you need Delve symbols in dev. Smaller zips load faster on cold start.bootstrap at zip root for provided.al2023. Wrong names fail at runtime with opaque errors.sync.Once, not in init(). Keeps unused code paths off the cold path.context.Context from the platform into all SDK calls. Honors API Gateway, Cloud Run, and client disconnect deadlines.context.WithTimeout slightly below platform limits. Return structured errors before hard kills./tmp on Lambda. Treat instance storage as ephemeral.* admin policies on runtime identities.--allow-unauthenticated defaults after spikes.govulncheck on modules touching cloud SDKs. Supply-chain issues land in credential and HTTP paths first.log/slog to stdout/stderr. CloudWatch, Cloud Logging, and App Insights parse structured fields.ReadHeaderTimeout on every http.Server in containers. Blocks slowloris before handlers run.http.Server.Shutdown. Cloud Run and ECS send terminate signals before SIGKILL.p99 end-to-end latency split by cold vs warm path.
If cold dominates, fix packaging and init before raising memory spend.
Dev can be looser for velocity but must not share prod roles or secrets.
Use separate accounts or namespaces with parallel policies.
Layers help polyglot teams share agents; pure Go binaries rarely need layers unless distributing observability extensions.
Prefer smaller single binaries first.
Chaos-test duplicate SQS deliveries and HTTP retries in integration tests; assert one visible side effect.
When you need operators, custom CRDs, service mesh features, or uniform multi-team cluster standards that managed functions cannot host.
Yes - leave headroom above heap live size; OOM kills are harder to debug than slightly higher memory settings.
Stack versions: This page was written for Go 1.26.x (Green Tea GC default, go fix modernizers - verify patch at build), chi (latest - verify at build), gin (latest - verify at build), echo (latest - verify at build), google.golang.org/grpc (latest - verify at build), sigs.k8s.io/controller-runtime (latest - verify at build), kubebuilder (latest - verify at build), tinygo (latest - verify board targets at build), wazero (latest - verify at build), and golangci-lint (latest - verify linter set at build).
Reviewed by Chris St. John·Last updated Jul 19, 2026