Adopting Bazel for Web at Scal... Note

Adopting Bazel for Web at Scale

Airbnb recently adopted Bazel, Google's open source build tool, as their universal build system across backend, web, and iOS platforms. The company's large-scale web monorepo, consisting of over 11 million lines of code, presented challenges with bespoke build scripts and caching logic that were difficult to maintain and scaled poorly. To address these issues, Airbnb migrated to Bazel, which offered sophistication, parallelism, caching, and performance. The migration process began in 2021, but there was no publicized industry precedent for integrating Bazel with web at scale outside of Google. The team had to overcome performance issues when transmitting large files to the remote environment and established migration principles that included improving or maintaining overall performance and reducing the impact on developers contributing to the monorepo during the transition.To prepare the repository for Bazel, the team performed cycle breaking and automated BUILD.bazel file generation. They also migrated CI jobs to Bazel, starting with type checking, linting, and unit testing. The team enabled TypeScript, ESLint, and Jest, and introduced caching to reduce input size and improve performance.To prevent backsliding, the team moved tests from "hidden" to "required" via a rule attribute and ensured a single source of truth by not running tests under the Jest setup being replaced. They also wrote a script to compare before and after Bazel to determine migration-readiness using metrics such as test runtime, code coverage stats, and failure rate.In tandem with the CI migration, the team ensured that developers can run Bazel locally to reproduce and iterate on CI failures. They delivered a local Bazel experience that is on par with or superior to the existing developer experience and performance, allowing developers to continue using familiar tools and opt into Bazel when beneficial.