Back to course

Optimizing Go Binaries for Production

Go (Golang) for Cloud-Native Microservices

Shrinking the Binary

For cloud environments, every megabyte counts. Use linker flags to strip debug information.

bash go build -ldflags="-s -w" -o main .

  • -s: Omit the symbol table.
  • -w: Omit DWARF debugging information.

This can reduce your binary size by up to 30%.