Building Uber’s Go Monorepo with Bazel

Zhongpeng Lin
10 min readintermediate
--
View Original

Overview

The article discusses Uber's transition to using Bazel for their Go monorepo, detailing the challenges faced with previous build systems and the improvements made through Bazel's capabilities. It highlights the significant growth in the number of Go commits and active developers since adopting the monorepo approach.

What You'll Learn

1

How to leverage Bazel for building large Go codebases

2

Why using a monorepo can improve build efficiency

3

When to use Gazelle for generating Bazel rules

Prerequisites & Requirements

  • Understanding of build systems and Go programming
  • Familiarity with Bazel and Gazelle(optional)

Key Questions Answered

What benefits did Uber see from switching to Bazel for their Go monorepo?
Uber experienced significant improvements in build efficiency and developer productivity after transitioning to Bazel. The number of Go commits per month increased from less than 100 to nearly 10,000, and active developers grew from under 10 to nearly 900, showcasing the effectiveness of the monorepo approach.
How does Uber manage dependencies in their Go monorepo?
Uber uses Bazel's go_repository rules to manage external Go modules, allowing for efficient dependency handling. Gazelle generates these rules automatically based on the go.mod and go.sum files, streamlining the process of integrating external libraries into their build system.
What challenges did Uber face with their previous build systems?
Uber's initial use of Make and the default Go build system could not meet the demands of their growing codebase. As projects migrated to a monorepo model, the limitations of these tools became apparent, prompting the need for a more robust solution like Bazel.

Key Statistics & Figures

Number of Go commits per month
nearly 10,000
This increase reflects the rapid adoption and growth of the Go monorepo since its launch.
Number of active Uber engineers developing in the Go monorepo
nearly 900
This growth indicates the expanding use and importance of the Go monorepo within Uber.
Total files in the Go monorepo
over 70,000
This number demonstrates the scale and complexity of Uber's Go codebase.

Technologies & Tools

Build System
Bazel
Used for managing the build process of Uber's Go monorepo.
Build Tool
Gazelle
Automates the generation of Bazel rules for Go packages.

Key Actionable Insights

1
Transitioning to a monorepo can significantly enhance collaboration among teams by centralizing code management.
This approach allows for better visibility of dependencies and encourages shared practices, which can lead to improved code quality and faster development cycles.
2
Utilizing Bazel's remote cache can drastically reduce build times across distributed teams.
By sharing build artifacts, teams can avoid redundant builds, allowing for more efficient use of resources and quicker feedback loops.
3
Regularly contributing to open source projects like Bazel can enhance your team's capabilities and address specific needs.
Uber's contributions to Bazel not only improved their own workflows but also benefited the wider community, fostering collaboration and innovation.

Common Pitfalls

1
Failing to maintain build rules can lead to inconsistencies and errors in the build process.
As the number of packages grows, it's crucial to automate rule generation to avoid manual errors and ensure that all dependencies are correctly managed.
2
Neglecting to utilize Bazel's caching features can result in longer build times.
Without leveraging remote caching, teams may experience redundant builds, which can slow down the development process significantly.

Related Concepts

Monorepo Management Strategies
Bazel Build System Features
Go Programming Best Practices