The update that broke everything on a Friday afternoon
A developer on a small team ran a routine update one Friday afternoon: one library, one minor version bump, the kind of change that should be boring. The tests passed, the build went green, she deployed and went home. On Monday morning the login page was blank for a subset of users. The culprit was a library three layers down the dependency tree — a package the team had never heard of. The update had changed how that deep dependency handled a date format, and the login flow showed it first.
That story is not unusual. The damage rarely comes from the library you chose. It comes from the ones you never chose, the versions you never pinned, and the updates you never reviewed. Dependency management is keeping that whole web under control — and modern projects stand on hundreds of libraries, not a handful.
What a dependency actually is
A dependency is any piece of code your project relies on that you did not write. When your application needs to hash a password or validate an email address, you can write that code or take it from a library someone else maintains. Almost every team chooses the library: writing a password-hashing routine from scratch is a bad idea for almost everyone, and the established library has been reviewed, tested, and attacked by thousands of people. Reusing it is safer than reinventing it.
That trade has a cost: trust. When you add a dependency, you let someone else's code run inside your application, with the same access your application has. A library that reads files can read yours; one that makes network requests can make them from your servers. Dependency choices deserve the same care as hiring decisions: you are bringing outside code into your house and giving it a key.
Dependencies come in flavours. Direct dependencies are the ones you chose and listed in your project's manifest — the package.json, requirements.txt, Gemfile, go.mod, or pom.xml that records what your project needs. Transitive dependencies are the ones your dependencies need, which arrive without anyone on your team ever deciding on them. A typical web project might list forty direct dependencies and end up with eight hundred packages once the transitive ones are counted. That gap is where most of the risk lives. Runtime dependencies ship with your application; development dependencies exist only while you build and test, and a vulnerability in the first is a different problem from one in the second.
How a project ends up with hundreds of them
No team sets out to have eight hundred dependencies. It happens one small, reasonable decision at a time: a date library here, a form-validation library there, a charting library for the new feature. Each addition solves a real problem in ten minutes, and each one feels too small to argue about.
The trouble is that dependencies do not stay small. A library that does one thing often depends on three more libraries, which depend on others, and a single install of a popular framework can pull in hundreds of packages — most of them tiny utilities that do things like check whether a value is a string. The JavaScript ecosystem is the extreme case: it favours small, single-purpose packages, and the npm registry holds well over two million.
Each dependency is a small loan, and the slow accumulation of that cost has a name: technical debt. It saves time today and charges interest every month after — updates to review, vulnerabilities to patch, breaking changes to work around. A project with twenty dependencies can carry that interest easily. A project with eight hundred needs a system for it.
Before adding a dependency, ask whether the job is worth a permanent relationship: small, stable jobs are often twenty lines you write yourself, while hard, security-sensitive ones — cryptography, authentication — belong to an established library.
Lockfiles: the one file that keeps your builds honest
Every team has lived through this: the build works on one developer's machine and fails on another's, with the same code and commands. The usual cause is that the two machines installed different versions of the same dependencies — one developer got 2.4.1 last month, another got 2.4.3 today, and something small changed. Nothing in the code changed. The environment changed underneath it.
A lockfile fixes this. When you install dependencies, the package manager writes a file — package-lock.json in Node, Pipfile.lock or poetry.lock in Python, Gemfile.lock in Ruby, go.sum in Go, Cargo.lock in Rust — that records the exact version of every package installed, transitive dependencies included. From then on, every install reproduces those exact versions, on your laptop, in CI, and in production.
Three habits make lockfiles work. Commit the lockfile to version control; one sitting only on a single developer's machine helps nobody. Never edit it by hand — it is generated. And use the install command that respects it, such as npm ci in CI, so a build fails loudly if the lockfile and the manifest disagree.
The most common mistake is treating the lockfile as optional. Without it, builds are not reproducible, and "it works on my machine" becomes a regular incident. The second most common mistake is the opposite: committing the lockfile and then never updating it. A two-year-old lockfile pins your project to two-year-old code, with two years of known vulnerabilities. Pinning is not the same as freezing — the point is to make updates deliberate, not to prevent them.
Semantic versioning, and why it only works when people follow it
Most libraries communicate changes through version numbers, using the same scheme: semantic versioning, or semver. The version is three numbers — major, minor, patch. A patch release, like 2.4.1 to 2.4.2, fixes bugs and should change nothing else. A minor release, like 2.4.2 to 2.5.0, adds features but stays backwards compatible. A major release, like 2.5.0 to 3.0.0, is allowed to break things. The full rules are at semver.org, and the scheme was formalised by Tom Preston-Werner, one of GitHub's co-founders.
That is the theory. In practice, semver is a promise, and promises get broken. A maintainer releases a "minor" update that changes a default, renames a function, or drops support for an older runtime, and a thousand projects break. Sometimes the maintainer did not realise the change was breaking. Sometimes the project is a one-person side project, and version numbers go up whenever the author feels like it. Semver works well for mature, well-run projects, and unreliably for everything else.
This is why version ranges matter. You can declare an exact version, like 2.4.1, or a range, like ^2.4.1, which means "any version from 2.4.1 up to, but not including, 3.0.0". A range says you trust the maintainer's semver discipline. An exact pin says you do not, or that this library has burned you before. Neither is wrong in itself; the mistake is choosing without thinking. Use ranges for large, stable projects with a track record of careful releases, and exact pins for small or fast-moving libraries and anything that has broken you before. And read the changelog before accepting a major version bump — it is the maintainer telling you something is going to break.
Updating without the fear
The standard advice is to keep dependencies updated; the standard reality is that most teams do not, because updating is frightening. Every update is a chance that something breaks, and the longer you wait, the bigger the pile gets. This is a vicious circle, and it is how projects end up running a framework version from three years ago, with known vulnerabilities, because nobody wants to touch it.
Automation breaks the circle. Tools like GitHub's Dependabot and Mend's Renovate watch your repositories, and when a new version of a dependency appears, they open a pull request that updates it — often with the changelog included. Instead of a quarterly chore that takes a week, updating becomes a stream of small pull requests, each changing one library and running through your test suite on its own.
Treat those pull requests like any other change. Merge patch updates quickly; they are usually safe, and they keep security fixes flowing in. Review minor updates with a glance at the changelog. Hold major updates for a planned piece of work, because they need real testing. And configure the tool to group updates sensibly — a dozen separate pull requests for twelve tiny patch bumps is noise, and a team that gets noise stops reading it. Most teams end up with a weekly batch for routine updates and immediate ones for security fixes. Running the test suite on every one of these pull requests is what makes it safe, and CI/CD pipelines turn that check into a gate that runs the same way every time.
Transitive dependencies: the packages you never chose
The hardest part of dependency management is that most of your dependencies are not yours. You chose a web framework; the framework chose a router, which chose a path-matching library, which chose a string utility — code written by four different people, three of whom you have never heard of.
The left-pad incident of March 2016 shows how fragile this gets. A developer named Azer Koçulu, in a dispute with npm over a package name, unpublished all of his packages — more than two hundred of them, including a tiny eleven-line utility called left-pad. Thousands of projects depended on it indirectly, and their builds started failing within hours. npm changed its rules afterwards so packages with dependents cannot be unpublished the same way, but the underlying depth has only grown since.
You cannot eliminate transitive dependencies, but you can see them. Every package manager has a command that prints the tree: npm ls, pip show, cargo tree, go list -m all. Run it on your own project some time. The first time most developers do this, the number surprises them — and that surprise is useful: it is the difference between knowing you have dependencies and knowing what they are.
A few habits help. Prefer libraries with small dependency trees: when two libraries do the same job, the one that brings in three packages is a better bet than the one that brings in forty. Watch for duplication — projects often end up with three different versions of the same library, pulled in by different parents, which means a larger bundle and a larger surface for bugs. And audit the tree after adding a new direct dependency; a library that looks light on its own can drag in a heavy tree, and it is easier to swap it out on the day you add it than six months later.
Auditing for vulnerabilities
Dependencies are the most common way vulnerabilities enter a project. You can write careful code, review every pull request, and run every test — and still ship a known vulnerability, because it arrived inside a library you installed two years ago and never looked at again. In December 2021, a vulnerability in Apache Log4j 2, a Java logging library used across enterprise systems, allowed attackers to run arbitrary code on affected servers. The flaw, known as Log4Shell, was rated at the highest possible severity, and organisations spent weeks finding every place it was hiding — including inside software they had bought, not built. The Equifax breach of 2017 followed a similar pattern: an unpatched flaw in Apache Struts gave attackers a way in, though the patch had been available for months.
Finding these problems is largely automated now. Package managers ship with audit tools — npm audit, pip-audit, cargo audit, bundle audit — that compare your installed versions against databases of known vulnerabilities. GitHub's Dependabot does the same from the repository side. Tools like Snyk and OWASP Dependency-Check go further, scanning containers and build artefacts too.
The workflow is simple; the hard part is doing it regularly. Run an audit in CI on every build, so a new vulnerability is caught the day it is published. Treat critical vulnerabilities as incidents, with the same urgency as a production outage. And record the exceptions: sometimes a flagged vulnerability does not apply — the vulnerable function is never called. Note the reasoning in the repository, with a date, so the next person to see the warning does not have to re-investigate it.
It is worth understanding what auditing cannot do. An audit tells you about vulnerabilities that are known and recorded. It tells you nothing about the ones nobody has found yet, or about a package that was deliberately compromised. In 2018, a popular npm package called event-stream received a malicious update from someone who had been given maintainer access, and the code sat inside it for weeks, targeting a specific cryptocurrency wallet. No audit tool flagged it, because the flaw was not in any database — it was new malicious code. Auditing is one layer, not the whole answer. The other layers are the ones this article is about: choosing carefully, keeping the tree small, and knowing what is in it. Supply chain attacks are the wider version of this problem, and dependency auditing is one of the cheapest defences against them.
Vendoring, pinning, and when the package manager is not enough
For most projects, a package manager and a lockfile are enough. For some, they are not. Sometimes you need stronger guarantees than a registry can give you, and the answer is usually vendoring: copying the dependency's source code into your own repository, so your build does not depend on an outside service being available.
Vendoring makes sense in a few specific cases. If your software has to build without internet access — an air-gapped system, a factory floor — you cannot fetch packages at build time. If a dependency is critical and maintained by one person who might walk away, a vendored copy means their decision cannot break your build. And if you need to patch a library, vendoring gives you a place to keep that patch, visible and versioned, instead of hiding it in a post-install script.
The price is real. Vendored code does not update itself. When a security fix lands upstream, you have to notice it, pull it in, and check that your patch still applies. A vendored library is also code your team now owns — someone has to understand it when it breaks. Teams that vendor carelessly end up with a repository full of frozen, ancient libraries that nobody dares to touch — the same problem as a stale lockfile, with a manual update mechanism.
Knowing when to let a dependency go
The last skill in dependency management is subtraction. Projects accumulate libraries and almost never shed them. A feature gets removed, but the library it needed stays in the manifest. A library gets replaced, but the old one stays installed, because removing it feels risky and nobody wants to be the person who breaks the build by deleting a line.
The result is a manifest full of packages that nothing uses. They still get downloaded, audited, and flagged in vulnerability alerts, and they confuse every new developer who reads the file. Removing them is low-risk work with a real payoff, and it should be a routine habit, not a special project.
Start with the easy cases: tools exist that find unused dependencies — depcheck for JavaScript, pip-autoremove and vulture for Python, and similar tools elsewhere. They are not perfect, and they can flag a package used indirectly or through a configuration file, so check each result before deleting anything. But they will find the obvious dead weight, and there is usually more of it than anyone expects.
Then apply a harder test to the dependencies you do use: what would it cost to replace this with code we write ourselves? If the answer is an afternoon, the library may not be earning its place. When was the last release? A library with no release in three years and a pile of open issues is a warning sign — not proof that it is bad, but a reason to check whether anyone is still maintaining it. And what does it do for us now, as opposed to when we added it? A library that was essential two years ago can become a convenience today.
There is also a question of trust. Open source software runs on the goodwill of maintainers, many of them unpaid volunteers. A library maintained by one tired person is a different bet from one maintained by a foundation or a company. Maintenance health matters as much as code quality, and teams often forget to check it until the maintainer announces they are stepping away.
Questions teams keep asking
How many dependencies is too many?
There is no number that fits every project. A web application with fifty direct dependencies and a few hundred transitive ones is normal; a command-line tool with the same count is over-built. The useful measure is not the count but the ratio of value to attention: can your team say, for each direct dependency, why it is there? If the answer is no for a third of them, the tree is too big for the team.
What do I do when a library I depend on is abandoned?
First, check whether it actually needs replacing. An abandoned library that does one simple, stable thing — parsing a format that has not changed in a decade — can run untouched for years. The danger is one in a fast-moving area: a web framework, an authentication library, anything touching security. If it needs replacing, look for a maintained fork first. If there is no fork, budget the replacement as real work, with tests, not an afternoon swap. And if you cannot replace it yet, vendor a copy so the source is under your control.
Is it ever worth writing something myself instead of using a library?
Yes, and more often than the ecosystem's habits suggest. Compare the cost of writing it against the cost of owning the dependency for years. A small utility with a stable specification — formatting a duration, slugifying a title — is often twenty lines of code you fully understand, against a package that brings its own dependencies, release schedule, and risk. The exception is anything security-sensitive or deeply complex: nobody should write their own cryptography, HTML sanitiser, or date library. The line between those two cases is the judgement that makes dependency management a skill rather than a checklist.
What to do next
Dependency management is not a project with an end date. It is a habit, and it works best when the steps are small enough to do without a meeting. Here is a starting list:
- Commit a lockfile and make CI install from it. - Turn on automated update pull requests, and merge patch updates the week they arrive. - Run a vulnerability audit in CI, and treat critical findings as incidents. - Print the dependency tree and ask whether each direct dependency is still earning its place. - Remove the unused
Comments
Post a Comment