1. Introduction
이미 “dependencies are described in go.mod, and Go will download everything on its own”라는 아이디어를 좋아하게 되었다면, vendor/ 폴더의 등장은 마치 과거에서 갑자기 돌아온 것처럼 느껴질 수 있습니다. “왜 남의 코드를 저장소에 복사해야 하죠? 우리가 아카이브 관리자도 아닌데요?” 하지만 현실은 곧바로 “인터넷이 끊겼다”, “프록시가 안 된다”, “프로덕션에서는 네트워크에 접속하면 안 된다”, “2년 뒤에 라이브러리가 사라져도 빌드가 재현되어야 한다” 같은 상황을 만들어 냅니다.
Vendoring은 마치 트렁크에 넣어 두는 “비상용 dependency kit”과 같습니다. 보통은 없어도 괜찮지만, 어떤 조건에서는 이상한 선택지가 아니라 유일한 이동 수단이 됩니다. 그리고 중요한 것은 “어떻게 켜는가”만이 아니라, 빌드의 동작과 팀의 일상에서 정확히 무엇이 바뀌는지를 이해하는 것입니다.
2. What is vendor/, and what changes during build
vendor/는 외부 dependencies의 소스 코드가 들어가는 저장소 안의 디렉터리입니다. 보통 go.mod에 require로 적힌 것들과 그 전이적 dependencies가 여기에 포함됩니다. 즉, 여러분은 다른 사람의 코드를 “자기 프로젝트 옆에” 보관해서, 빌드가 dependencies를 네트워크나 module cache가 아니라 저장소에서 가져오게 합니다.
이것은 우연한 전통이 아닙니다. Go 커뮤니티는 모듈 이전부터 이미 “dependencies를 저장소에 복사한다”는 접근을 적극적으로 사용했고, 수동으로 하기에는 너무 불편하고 취약했기 때문에 도구 수준의 지원까지 추가했습니다. godep, glide 같은 외부 툴이 dependencies를 저장소로 복사했고, 이후 Go에 vendor 디렉터리 지원이 명시적으로 추가되어 이 시나리오가 더 쉬워졌습니다.
중요한 점: vendor/는 go.mod/go.sum의 대체가 아닙니다. 이것은 새로운 버전 선택 시스템이 아니라, 단지 “소스 코드의 로컬 복사본”입니다.
How vendor/ affects import resolution
vendor/를 추가한다고 해서 코드의 imports를 다시 쓰는 것은 아닙니다. 여러분의 코드는 여전히 이렇게 씁니다:
import "github.com/google/uuid"
이 점이 핵심입니다. import path는 “모듈 세계에서 이 패키지가 어떻게 불리는가”이고, vendor/는 빌드 과정에서 그 import path에 대한 소스 코드를 “어디서 가져올 것인가”만 정합니다.
변화는 도구 go의 내부에서 일어납니다. 빌드와 테스트 시, 모드에 따라 vendor/를 dependencies의 소스로 사용할 수 있습니다.
Visual scheme (roughly):
go build / go test
|
v
Import resolution (import path -> sources)
|
+--> option A: take from module cache (normal mode)
|
+--> option B: take from ./vendor/... (vendoring mode)
즉, vendor/는 Go 코드의 문법이 아니라 dependencies의 해석 방식에 영향을 줍니다. 즉, 실제로 패키지를 어디에서 가져오느냐가 바뀝니다.
3. vendor/, module cache, and replace: similar, but different in meaning
헷갈리지 않으려면, dependencies 코드가 어디에 있는지와 무엇을 사용하기로 결정하는지를 보여 주는 “상식 표”를 두는 것이 좋습니다.
| Approach | Where the dependency code lives | What you pin | Typical motive |
|---|---|---|---|
| Ordinary modules | Global module cache (downloaded once and reused) | go.mod + go.sum | “Normal life”: clean, compact, predictable |
|
An alternative source (often a local folder on disk) | Replacement rule in go.mod | Local development/debugging of a dependency |
|
Directly in the repository (./vendor/...) | Snapshot of dependency source code | Offline/audit/hermetic build |
Note that replace changes the “delivery route” of a dependency and can make the project depend on the folder structure of a specific machine, while vendor/ makes the repository self-sufficient in terms of dependency source code. At the same time, go.mod/go.sum still remain the “truth about versions”.
4. How vendor/ appears, and what is inside
The vendor/ folder should not appear “manually out of nowhere”. In a normal project, Go tools generate it (for example, with a command like go mod vendor). I say “like” intentionally, because the important thing is to understand the idea: vendoring is a reproducible snapshot, not a place for manual creativity.
A typical structure looks roughly like this:
todoapp/
go.mod
go.sum
main.go
internal/...
vendor/
github.com/google/uuid/...
golang.org/x/text/...
modules.txt
The file modules.txt (often present) is a kind of registry that helps tools understand which modules and versions you have vendored.
And another important detail: having vendor/ does not cancel the fact that dependency management commands still work through go.mod/go.sum. Even if the build takes source code from vendor/, the commands go get and go mod tidy still remain dependency-management commands and continue to modify go.mod and go.sum, because their job is version selection, import synchronization, and checksum control.
5. When vendor/ is needed, and when it becomes a burden
There is a temptation to enable vendor/ “just in case,” the way people sometimes install antivirus on antivirus so the virus will definitely get scared. But vendor/ is not a free feature: it has a cost, so it is better to understand the motives.
The most common real-world scenario is restricted or blocked network access. For example, CI/CD builds or builds in a closed network where dependencies cannot be downloaded during the build. Then vendor/ turns the project into a “box where everything is already inside”.
The second scenario is audit and control. Sometimes organizations want to keep an exact snapshot of dependency source code next to the code: so they can guarantee that the binary was built from specific sources, and those sources are available without external services.
The third scenario is long-term reproducibility. Modules, proxies, repositories — all of that can disappear or become unavailable. But a repository with vendor/ (if it is maintained properly) remains self-sufficient.
The cost of vendor/: size, noise, and discipline
If vendor/ were pure magic with no downsides, all projects would have vendor/ by default, and we would not even be discussing this lecture (instead, there would be a lecture about growing potatoes on Mars). But the downsides of vendoring are very down to earth.
- First, the repository gets bloated. Sometimes a lot. This affects clone size, operation speed, and the “entry threshold” for newcomers: a person opens the project and sees ten thousand files before writing a single line.
- Second, noisy diffs and merge conflicts appear. Even if you changed one dependency, vendor/ may update with a large set of files. For the team, this means that “dependency update” becomes a separate event that must be read and reviewed.
- Third, vendor/ requires discipline: it becomes stale very easily. You can update go.mod and forget to update vendor/, and then you effectively have two sources of truth in the project that contradict each other. And in a contest between two “truths,” the one that crashes louder in CI usually wins.
6. Mini example: UUID in a training todoapp and vendoring
Imagine that our training app is a console todoapp that we are gradually developing. Suppose we want to generate task IDs not manually, but through a UUID library. For the example, let’s take the popular package github.com/google/uuid (you can replace it with any other external package — the logic will be the same).
Let’s add a small wrapper package so we do not have to carry UUID details around the entire codebase:
package id
import "github.com/google/uuid"
func New() string {
return uuid.NewString()
}
Now in the task creation code we can do something like this:
package todo
import "example.com/todoapp/internal/id"
func NewTask(title string) Task {
return Task{ID: id.New(), Title: title}
}
Note: the import remains ordinary, “module-based”. No vendor/... appears in the code — and that is correct.
After that, go.mod will get a require for the needed module/version (this is done by go get or IDE tools). And if you decide to use vendoring, you generate the vendor/ folder, and the project begins to contain a copy of that dependency’s source code.
The key point here is that vendor/ is not an alternative way to import a package in code, but an alternative way to store dependency source code nearby so the build can rely on it. And even with vendor/ present, dependency management still goes through go.mod/go.sum: the commands go get and go mod tidy still modify these files, because that is their job.
7. How to live with vendor/ as a team
When a project uses vendor/, it is good for the team to follow a predictable ritual. Otherwise, a “snowball” of unsynchronized changes quickly appears: one developer updates go.mod, another pulls the branch and gets strange mismatches, and a third accidentally commits a change directly into vendor/ (yes, that happens too, and it is its own genre of pain).
Usually the process looks like this: you change dependencies at the “module level” (that is, through go.mod), then you clean up go.sum, and only then do you update vendor/ as a snapshot of the current state. The sequence matters: first we choose versions and fix them in the module files, and only then do we make a “copy for offline use”.
And it helps to keep a simple frame in mind: vendor/ is the “sources nearby” layer, not a new dependency manager. Versions are chosen and fixed in go.mod, verifiability is provided by go.sum, and vendor/ is a way to make the build less dependent on the network and external infrastructure.
8. Typical mistakes when working with vendor/
Mistake #1: editing code directly inside vendor/ “because it is fast”.
At first it seems like you are a genius: “I fixed a bug in a dependency in 30 seconds.” Then it turns out that you are now maintaining a dependency fork by hand, but without the fork, without history, without documentation, and without any chance of upgrading properly. If you really need to patch a dependency, that is a separate deliberate story, not a sudden edit in vendor/.
Mistake #2: thinking that vendor/ replaces go.mod and go.sum.
This mindset breaks your model of how things work: you start ignoring go.mod, and then you wonder why tools keep changing go.sum, why the IDE complains, and why the dependency update did not “sink in” to the build. vendor/ is a copy of source code, while go.mod/go.sum remain the declaration of dependencies and their checks.
Mistake #3: updating go.mod but forgetting to update vendor/.
This is one of the most unpleasant kinds of desynchronization: the repository contains vendor/ with old contents, while go.mod already requires something else. As a result, the build takes one thing in “one mode” and another thing in “another mode”, and “it works on my machine” stories begin. This is especially painful when CI is configured differently from local development.
Mistake #4: treating vendor/ as a default “development speed-up”.
Sometimes it seems: “If dependencies are in the repository, it must be faster.” In practice, what usually gets faster is only offline builds, while the price is a larger repository and more complicated reviews. Vendoring is usually a solution for constraints (network, audit, policy), not a universal optimization.
Mistake #5: committing vendor/ without understanding “why”, just because “it is trendy”.
In some teams vendor/ is a critical part of the process; in others it is extra baggage. If you do not have requirements for hermetic builds and do not have problems accessing modules, vendor/ can easily become a suitcase without a handle: hard to carry, and a pity to throw away.
GO TO FULL VERSION