Bazel
Google's large-scale build system
Google's large-scale build system
Bazel is a build and test tool that Google released as open source in 2015, based on its internal build system Blaze. It was designed to efficiently build Google-scale monorepos with millions of lines of code and thousands of developers.
Its key features are reproducible builds and incremental builds. Because all build inputs are declared explicitly, the same inputs always produce the same results. Only the changed parts are rebuilt, so build times stay fast even in large codebases.
BUILD files are written in Starlark (a Python-like language), and multiple languages (Java, C++, Go, Python, TypeScript, etc.) are unified under a single build system. Remote caching and remote execution allow the whole team to share build results and enable distributed builds.
In practice, it shines in large monorepos, complex dependency graphs, and multi-language projects. However, it has a learning curve and can be overhead for small projects. A strategic approach is needed when migrating from Gradle or Maven.
# BUILD.bazel - Python ์๋น์ค ๋น๋ ์ ์
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
load("@rules_docker//python:image.bzl", "py_image")
# ๊ณต์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
py_library(
name = "payment_lib",
srcs = glob(["src/**/*.py"]),
deps = [
"//common:utils",
"@pip//grpcio",
"@pip//protobuf",
],
visibility = ["//visibility:public"],
)
# ๋ฉ์ธ ์ ํ๋ฆฌ์ผ์ด์
py_binary(
name = "payment_service",
srcs = ["main.py"],
deps = [":payment_lib"],
)
# Docker ์ด๋ฏธ์ง ๋น๋
py_image(
name = "payment_image",
base = "@python3_base//image",
binary = ":payment_service",
)
# ํ
์คํธ
py_test(
name = "payment_test",
srcs = ["tests/test_payment.py"],
deps = [
":payment_lib",
"@pip//pytest",
],
)
Senior: "A full monorepo build takes over 20 minutes. I'm planning to adopt Bazel for incremental builds and use a remote cache to reduce CI build times as well."
Junior: "Is it easy to migrate an existing Maven project?"
Senior: "With rules_jvm_external you can keep using your Maven dependencies as they are, but writing the BUILD files is a separate task. Let's switch over gradually."
Interviewer: "Why are Bazel's hermetic builds important?"
Candidate: "A hermetic build declares all dependencies explicitly, so it is not affected by the host environment. The same code produces an identical binary wherever it is built, which guarantees reproducibility and also ensures the accuracy of remote caching."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free
Reviewer: "The visibility of this target is //visibility:public. Is it actually used outside this package?"
Developer: "Ah, it would be better to specify only the places that need it. I'll change it to visibility = [\"//services/payment:__subpackages__\"]."