tezvyn:

Monorepo workspaces vs private npm packages

AI-drafted, machine-checkedSource: interviewadvanced
WHAT IT TESTS

tradeoffs of code-sharing strategies.

OUTLINE

workspaces give atomic cross-service changes and instant local linking but couple release cadence; private packages give versioned isolation but add publish overhead and version drift.

WHAT THIS TESTS This evaluates architectural judgment about organizational and technical tradeoffs when many services share code, rather than dogmatic preference.

A GOOD ANSWER COVERS A monorepo with workspaces stores all services and shared libraries in one repository. The package manager symlinks internal packages so a consumer always uses the local source without a publish step, which makes a breaking change to a shared model and the updates to every consumer happen in one atomic commit and one review. You get consistent tooling, easy global refactors, and a single source of truth. The downsides are heavier CI that must understand the dependency graph, potential for tight coupling, and the need for tooling to scope builds and releases. Publishing private npm packages keeps services in separate repos that consume the shared library by version. This gives strong isolation, independent release cadence, and clear ownership boundaries, which suits autonomous teams. The cost is publish-and-bump overhead, slower iteration on the shared code, and version drift where consumers run different, possibly stale versions, risking integration bugs.

COMMON WRONG ANSWERS Declaring monorepos or polyrepos universally superior, ignoring the atomic-change benefit of workspaces, or overlooking version drift and publish friction in the package approach. Another error is conflating a monorepo with a single deployable.

LIKELY FOLLOW-UPS How tools like changesets or release pipelines manage versioning, how to scope CI to changed packages, how pnpm's strict linking helps, and how to combine the two by publishing from a monorepo.

ONE CONCRETE EXAMPLE If five tightly related services share a data model that changes often, workspaces let you edit the model and all five consumers in a single pull request, with everyone instantly on the new code. If instead independent teams own loosely coupled services, publishing the model as a versioned private package lets each team upgrade on its own schedule, at the cost of some teams temporarily running an older version until they bump it.

Read the original → yarnpkg.com

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.