Choosing a dependency
Every dependency is a trade, and the obvious heuristics pull in opposite directions. Balance them
deliberately.
- Force A — fewer dependencies is better. Each third-party library is attack surface, a
supply-chain risk, transitive bloat, a thing that can break or go unmaintained, and a version to
track. The standard library is always the first choice; a pile of micro-dependencies is a smell.
- Force B — don't reinvent the wheel. A library delegates a whole problem's maintenance to its
owner. Hand-rolled helpers for solved, non-trivial problems are our bug surface and our
maintenance burden forever, so prefer a good external library to an internal reimplementation
of something already well-solved.
These resolve into one rule:
Import rarely; when you do, pick the broad, trusted, well-maintained option and consolidate on
it. A batteries-included library from a reputable source that covers a whole domain beats a thin
wrapper that you'll have to supplement with three more libraries later. Fewer, better, broader
dependencies — not more, smaller ones.
Illustration. Prefer an ORM like bun (struct decoding, query building, migrations, hooks all
native, one maintainer) over a lower-level driver like pgx that needs extra third-party packages
bolted on for the same ergonomics: one broad, well-maintained dependency replaces several narrow
ones, fewer versions to track and one place to learn. Follow the reasoning pattern — pick per the
actual need, not by analogy.
The decision procedure
Work top to bottom; stop at the first answer that fits.
Is it already solved in-house? Standard library, a dependency already in go.mod /
package.json, or golib / nodelib? Use that. Adding a second library to do what an existing
one already does is the most common avoidable dependency.
Is it trivial and stable? A few lines, well-understood, unlikely to change (a tiny string
helper, a constant, a one-off transform)? Implement it internally — a dependency is not worth the
supply-chain and version cost here. (For Go libraries, also weigh write-go-kit's "should this
even live in golib?" bar.)
Is it a solved, non-trivial domain? Parsing, crypto, ORM/SQL, HTTP routing, validation,
serialization, UUID, time, retries, observability, etc. — these are where you buy, not build;
reimplementing them is how subtle bugs and security holes get in. Go to candidate evaluation.
Is it genuinely novel to our domain? No good library exists, or every candidate fails
evaluation? Implement internally — and design it so it could graduate into a library later
(write-go-kit).
Evaluating candidates (when buying)
Research each serious candidate against these, and write the comparison into the plan's build-vs-buy
section. The first three are gating; the rest are tie-breakers.
- Trust — who owns it? A reputable org, a foundation, or a healthy community beats a single
unknown maintainer. Trust is what makes "delegate the maintenance" safe.
- Maintenance & health — recent commits and releases, issues triaged, not archived, a real
changelog. An abandoned library is an internal implementation you don't control.
- Security — known CVEs / advisories, the size and trustworthiness of the transitive
dependency tree (a "small" library that drags in 40 packages isn't small), and supply-chain
hygiene (signed releases, pinned CI).
- Coverage — does it cover enough of the domain that you won't need to add more libraries
alongside it? This is the consolidation lever; weight it heavily.
- License — compatible with the repo's license and distribution. A blocker if not.
- Footprint & fit — binary/bundle size, API ergonomics that match our patterns, and how cleanly
it isolates behind our own abstractions if we ever need to swap it.
- Adoption — popularity is corroborating evidence of trust and longevity, not a goal in itself.
Research method — use the internet, from trusted sources
Never decide from memory. Search the web and read primary, trustworthy sources:
- The library's official docs and repository (README, changelog, release cadence, open issues).
- The package registry —
pkg.go.dev (Go), npmjs.com (JS) — for versions, dependents, and the
transitive tree.
- Security advisories — GitHub Advisory Database, the Go vulnerability database, npm audit data.
- Reputable comparisons and the broader community's experience — weighted below primary sources, and
always sanity-checked against the repo itself.
Prefer recent, primary information over old blog posts, and note your sources in the plan so the
human can verify the call.
Org policy hooks
- No
replace directives; exact version pins. Go deps are pinned to released tags and bumped by
Renovate — see manage-versions.
- Internal (a-novel / a-novel-kit) dependencies are a
manage-versions concern: SHA-pin while
developing, dependency releases first, consumer re-pins to the tag before merging.
- Tooling dependencies (generators, linters, test tools) stay isolated in their own
<tool>.mod / .sum files, never in the main go.mod, and are never go install-ed globally —
see write-go's tools policy.
- Kit repos hold a stricter bar than services for taking on any dependency (
write-go-kit).
Output
A short, justified recommendation that drops into the plan's build-vs-buy section: the need, the
options weighed (stdlib / existing / a named library / internal), the evaluation evidence with
sources, and the call with its reasoning. If the answer is "build internally," say why every buy
option fell short; if "buy," say why this library and not the narrower alternatives.
Examples
Build. Need: a 15-line helper that formats an internal ID into a display string, specific to our
domain. No external library matches without contortions, the logic is trivial and stable. Implement
it internally — a dependency here would add supply-chain risk for nothing.
Reuse. Need: structured logging in a new service. golib already exposes the org's logging
setup. Use it — adding a different logging library would fragment the codebase and duplicate a solved
concern.
(The buy-and-consolidate case is the bun-over-pgx illustration above.)
1---2name: choose-dependency3description: Decide whether a need is met by the standard library, an existing dependency, a new third-party library, or an internal implementation — and which package to pick when importing. Use it whenever a change adds a library, weighs build-vs-buy, swaps an internal helper for a dependency (or back), or picks between competing packages. Feeds plan-feature's build-vs-buy section.4---56# Choosing a dependency78Every dependency is a trade, and the obvious heuristics pull in opposite directions. Balance them9deliberately.1011- **Force A — fewer dependencies is better.** Each third-party library is attack surface, a12 supply-chain risk, transitive bloat, a thing that can break or go unmaintained, and a version to13 track. The standard library is always the first choice; a pile of micro-dependencies is a smell.14- **Force B — don't reinvent the wheel.** A library delegates a whole problem's maintenance to its15 owner. Hand-rolled helpers for solved, non-trivial problems are _our_ bug surface and _our_16 maintenance burden forever, so **prefer a good external library to an internal reimplementation**17 of something already well-solved.1819These resolve into one rule:2021> **Import rarely; when you do, pick the broad, trusted, well-maintained option and consolidate on22> it.** A batteries-included library from a reputable source that covers a whole domain beats a thin23> wrapper that you'll have to supplement with three more libraries later. Fewer, better, broader24> dependencies — not more, smaller ones.2526**Illustration.** Prefer an ORM like `bun` (struct decoding, query building, migrations, hooks all27native, one maintainer) over a lower-level driver like `pgx` that needs extra third-party packages28bolted on for the same ergonomics: one broad, well-maintained dependency replaces several narrow29ones, fewer versions to track and one place to learn. Follow the _reasoning pattern_ — pick per the30actual need, not by analogy.3132---3334## The decision procedure3536Work top to bottom; stop at the first answer that fits.37381. **Is it already solved in-house?** Standard library, a dependency already in `go.mod` /39 `package.json`, or `golib` / `nodelib`? Use that. Adding a second library to do what an existing40 one already does is the most common avoidable dependency.41422. **Is it trivial and stable?** A few lines, well-understood, unlikely to change (a tiny string43 helper, a constant, a one-off transform)? Implement it internally — a dependency is not worth the44 supply-chain and version cost here. (For Go libraries, also weigh `write-go-kit`'s "should this45 even live in `golib`?" bar.)46473. **Is it a solved, non-trivial domain?** Parsing, crypto, ORM/SQL, HTTP routing, validation,48 serialization, UUID, time, retries, observability, etc. — these are where you **buy, not build**;49 reimplementing them is how subtle bugs and security holes get in. Go to candidate evaluation.50514. **Is it genuinely novel to our domain?** No good library exists, or every candidate fails52 evaluation? Implement internally — and design it so it could graduate into a library later53 (`write-go-kit`).5455---5657## Evaluating candidates (when buying)5859Research each serious candidate against these, and write the comparison into the plan's build-vs-buy60section. The first three are gating; the rest are tie-breakers.6162- **Trust** — who owns it? A reputable org, a foundation, or a healthy community beats a single63 unknown maintainer. Trust is what makes "delegate the maintenance" safe.64- **Maintenance & health** — recent commits and releases, issues triaged, not archived, a real65 changelog. An abandoned library is an internal implementation you don't control.66- **Security** — known CVEs / advisories, the size and trustworthiness of the **transitive**67 dependency tree (a "small" library that drags in 40 packages isn't small), and supply-chain68 hygiene (signed releases, pinned CI).69- **Coverage** — does it cover enough of the domain that you _won't_ need to add more libraries70 alongside it? This is the consolidation lever; weight it heavily.71- **License** — compatible with the repo's license and distribution. A blocker if not.72- **Footprint & fit** — binary/bundle size, API ergonomics that match our patterns, and how cleanly73 it isolates behind our own abstractions if we ever need to swap it.74- **Adoption** — popularity is corroborating evidence of trust and longevity, not a goal in itself.7576---7778## Research method — use the internet, from trusted sources7980Never decide from memory. Search the web and read **primary, trustworthy** sources:8182- The library's **official docs and repository** (README, changelog, release cadence, open issues).83- The package registry — `pkg.go.dev` (Go), `npmjs.com` (JS) — for versions, dependents, and the84 transitive tree.85- **Security advisories** — GitHub Advisory Database, the Go vulnerability database, npm audit data.86- Reputable comparisons and the broader community's experience — weighted below primary sources, and87 always sanity-checked against the repo itself.8889Prefer recent, primary information over old blog posts, and **note your sources** in the plan so the90human can verify the call.9192---9394## Org policy hooks9596- **No `replace` directives; exact version pins.** Go deps are pinned to released tags and bumped by97 Renovate — see `manage-versions`.98- **Internal (a-novel / a-novel-kit) dependencies** are a `manage-versions` concern: SHA-pin while99 developing, dependency releases first, consumer re-pins to the tag before merging.100- **Tooling dependencies** (generators, linters, test tools) stay isolated in their own101 `<tool>.mod` / `.sum` files, never in the main `go.mod`, and are never `go install`-ed globally —102 see `write-go`'s tools policy.103- **Kit repos hold a stricter bar** than services for taking on any dependency (`write-go-kit`).104105---106107## Output108109A short, justified recommendation that drops into the plan's build-vs-buy section: the need, the110options weighed (stdlib / existing / a named library / internal), the evaluation evidence with111sources, and the call with its reasoning. If the answer is "build internally," say why every buy112option fell short; if "buy," say why this library and not the narrower alternatives.113114---115116## Examples117118**Build.** Need: a 15-line helper that formats an internal ID into a display string, specific to our119domain. No external library matches without contortions, the logic is trivial and stable. Implement120it internally — a dependency here would add supply-chain risk for nothing.121122**Reuse.** Need: structured logging in a new service. `golib` already exposes the org's logging123setup. Use it — adding a different logging library would fragment the codebase and duplicate a solved124concern.125126(The buy-and-consolidate case is the `bun`-over-`pgx` illustration above.)