# One Small Step Closer to Containerising Service Binaries

[Grab](https://yomu.fyi/company/grab) · Stan Halka · Feb 23, 2021

**Type:** Problem & solution

## Summary

Engineering teams at Grab initiated a transition to containerized microservices to standardize environments, enhance security, and decouple services from internal runtime tooling. During this migration, developers noticed that statically-linked Go service binaries were reaching bloated sizes over 100 MB. By analyzing the binaries using the open-source tool go-binsize-viz alongside the Go nm toolchain, the team visualized compiled symbols as interactive treemaps. This analysis revealed that 11 MB of unused message format symbols were being pulled in because a generic interface shared a directory with auto-generated streaming code. Restructuring the packages to isolate interfaces from generated code successfully decreased the binary size down to 78 MB.

## Context

During Grab's migration to a containerized microservice architecture, engineers noticed that statically-linked Go binaries were unexpectedly bloated to sizes over 100 MB, increasing container image size and deployment overhead.

## Approach / What changed

Engineers used the go-binsize-viz utility and Go's nm tool to generate treemap visualizations of binary symbols, pinpointed unused transitive dependencies caused by auto-generated stream message formats sharing a package directory with an interface, and restructured the code to decouple them.

## Takeaways

- Go imports all symbols defined within an imported directory and its transitive dependencies, rather than only the specifically referenced symbols.
- Placing a shared interface in the same directory as auto-generated streaming models caused services to needlessly compile 11 MB of unused message symbols into their binaries.
- Restructuring the flat package layout to separate generic interfaces from generated models reduced the target binary size from over 100 MB down to 78 MB.

**Tags:** [Deployment](https://yomu.fyi/topic/deployment), [Docker](https://yomu.fyi/topic/docker), [Go](https://yomu.fyi/topic/go), [Microservices](https://yomu.fyi/topic/microservices), [Refactoring](https://yomu.fyi/topic/refactoring)

[Read original post](https://engineering.grab.com/reducing-your-go-binary-size)
