Monorepos
Junior Questions
What are Pnpm Workspaces?
Pnpm workspaces provide native support for multi-package repositories without extra tools, using a shared lockfile and efficient symlinking to save disk space.
What problems does this solve?
- Pnpm is the modern standard for package management in large JS monorepos.
What is Lerna?
Lerna is one of the original tools for managing JavaScript projects with multiple packages. It is now maintained by the Nx team and integrates with Nx's build engine.
What problems does this solve?
- Understanding the history and current state of Lerna is important for legacy project maintenance.
What is a Monorepo?
A monorepo (monolithic repository) is a software development strategy where code for many projects is stored in the same repository.
What problems does this solve?
- Essential starting point for understanding modern large-scale software engineering.
What is the Single Source of Truth?
In a monorepo, there is one authoritative version of shared code and configurations, preventing the "dependency hell" of mismatched versions across different repositories.
What problems does this solve?
- Highlights the primary organizational benefit of the monorepo approach.
Mid-Level Questions
Code Sharing Patterns in Monorepos?
Code sharing is achieved via shared libraries, internal packages, and symlinking. This allows re-using domain logic, UI components, and utility functions across multiple applications.
What problems does this solve?
- One of the primary strategic reasons for adopting a monorepo structure.
Developer Experience (DX) in Monorepos?
Good DX is maintained via fast local execution, clear project boundaries, automated generator tools (scaffolding), and powerful IDE integrations that understand the project graph.
What problems does this solve?
- Emphasizes the human side of managing large codebases.
Docker in Monorepos?
Building Docker images in monorepos requires careful context management. Tools like `turbo prune` or `nx docker` help extract only the necessary code for a specific service to keep image sizes small and build times fast.
What problems does this solve?
- Practical operations knowledge for deploying monorepo-based microservices.
Future of Monorepos?
The future involves tighter integration with cloud-native build farms, AI-driven graph optimization, and "virtual" monorepos that provide a single-repo feel over distributed infrastructure.
What problems does this solve?
- Shows awareness of industry direction and emerging architectural patterns.
Monorepo Best Practices?
Key practices: keep libraries small and focused, use tags for project boundaries, enforce a single version policy, automate versioning/changelogs, and maintain a fast CI/CD pipeline.
What problems does this solve?
- Summarizes the essential rules for a successful monorepo implementation.
Monorepo Dependency Management?
Dependency management involves coordinating package versions across all projects. A common strategy is "one version rule," where all projects use the same version of a 3rd party library to avoid conflicts.
What problems does this solve?
- Crucial for avoiding "dependency hell" in large codebases.
Monorepo Versioning Strategies?
Strategies include "Fixed" versioning (all packages share one version) and "Independent" versioning (each package is versioned separately). Tools like Lerna/Changesets automate this.
What problems does this solve?
- Crucial for managing package releases in a multi-package repository.
Monorepo vs Polyrepo?
Polyrepo is the traditional approach of one repository per project/service. Monorepos centralize everything, facilitating code sharing and atomic commits across projects.
What problems does this solve?
- Evaluates ability to weigh architectural trade-offs between isolation and integration.
Peer Dependencies in Monorepos?
Peer dependencies are crucial for libraries in a monorepo to ensure they use the host application's version of a dependency (like React or Vue) instead of bundling their own.
What problems does this solve?
- Necessary for building portable libraries that don't bloat the final bundle.
Tooling Migration?
Migrating to a monorepo tool involves moving from ad-hoc scripts to structured task pipelines. It often starts with "wrapping" existing npm scripts and gradually adopting "integrated" build steps.
What problems does this solve?
- Evaluates practical experience in evolving a project's infrastructure.
What are Incremental Builds?
Incremental builds only recompile the projects that have changed (and their dependents), rather than the entire repository, significantly speeding up development.
What problems does this solve?
- Core concept for maintaining productivity in large codebases.
What is Change-based Testing?
Change-based testing (or "Affected" testing) uses the project graph to determine which tests need to run based on which files were modified, dramatically reducing CI time.
What problems does this solve?
- Key optimization for maintaining high velocity in large repositories.
What is Ghosting (Hoisting)?
Hoisting is the package manager behavior of moving deeply nested dependencies to the top-level `node_modules`. While this saves space, it can lead to "phantom dependencies" where code relies on unlisted packages.
What problems does this solve?
- Understanding how `node_modules` is structured is fundamental for troubleshooting build issues.
What is Nx?
Nx is a smart, fast, and extensible build system with first-class monorepo support and powerful integrations for JS/TS, Java, Go, and more.
What problems does this solve?
- Nx is the industry leader for "integrated" monorepos with advanced feature sets.
What is Task Caching?
Task caching stores the results of expensive operations (builds, tests, linting) and replays them instantly if the inputs haven't changed.
What problems does this solve?
- Fundamental optimization technique that justifies the use of monorepo tools.
What is Turborepo?
Turborepo is a high-performance build system for JavaScript and TypeScript monorepos, focused on simplicity and extreme speed via caching.
What problems does this solve?
- Turbo is the primary lightweight alternative to Nx, often preferred for Vercel/Next.js stacks.
What is a Project Graph?
A project graph is a visual representation of the relationships and dependencies between projects in a monorepo. Tools like Nx use this graph to optimize builds and task execution.
What problems does this solve?
- Visualization is key to managing complexity as the repository grows.
Senior Questions
Bazel vs Nx/Turborepo?
Bazel (Google) is an extremely powerful, language-agnostic build tool designed for Google-scale repos. Nx and Turbo are JS-centric and easier to set up, but Bazel offers unmatched performance and strictness for massive multi-language monorepos.
What problems does this solve?
- Differentiates between general tooling and ultra-scale specialized build systems.
CI Pipeline Optimization for Monorepos?
Optimization techniques include distributed task execution (DTE), horizontal scaling of build agents, and heavy use of remote caching to avoid re-doing work across different CI runs.
What problems does this solve?
- Senior-level DevOps knowledge for managing enterprise-scale codebases.
Deployment Strategies for Monorepos?
Strategies include "Atomic Deployments" (deploying all services together) or "Independent Deployments" (using tools to only deploy changed services). Independent deployment is usually required for large-scale microservice architectures.
What problems does this solve?
- Senior-level architectural knowledge of how code changes flow to production.
Monorepo Scale Issues?
Scaling issues include slow Git operations, IDE performance degradation, massive `node_modules` size, and complex CI/CD orchestration. Solutions include sparse checkout, virtual filesystems, and advanced build tool caching.
What problems does this solve?
- Senior-level understanding of the limitations and challenges of the monorepo approach.
Ownership & Access Control?
In a monorepo, fine-grained access control is often managed via `CODEOWNERS` files, ensuring that changes to specific projects or libraries require approval from the designated "owners."
What problems does this solve?
- Essential for maintaining security and code quality in large shared repositories.
What are Phantom Dependencies?
A phantom dependency occurs when a project uses a package that is not explicitly listed in its own `package.json`, but is available due to hoisting in the `node_modules` hierarchy.
What problems does this solve?
- Deep technical understanding of package manager behavior and build reliability.
What are Shared Libraries?
Shared libraries are packages containing reusable code (e.g., a design system or logging service) that are consumed by various apps in the monorepo. They are usually versioned and managed internally.
What problems does this solve?
- Senior-level question on how to modularize large applications for better maintainability.
What is Remote Caching?
Remote caching shares task results across a team and CI environment. If one developer builds a library, everyone else gets the cached result instead of building it themselves.
What problems does this solve?
- Critical for scaling CI/CD and large distributed engineering teams.
What is Sparse Checkout?
Sparse checkout allows a developer to only cloner or check out the parts of the repository they are actually working on, reducing disk space and improving Git performance in massive monorepos.
What problems does this solve?
- Key technique for managing massive repositories at companies like Google or Microsoft.