Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
69

Frontend System Design · Lesson 69 of 86 · 5 min

Monorepo Tooling: Nx and Lerna

You'll be asked how to scale a codebase across multiple teams and projects. This is the answer.

After this, you will be able to explain the trade-offs of a monorepo and justify choosing a tool like Nx by describing how its dependency graph and caching solve the core scaling problem: wasted computation.

When to reach for a monorepo

A monorepo is not just about putting all your code in one place. It's a strategy for managing dependencies between projects. You adopt a monorepo when you need to make atomic changes across multiple projects simultaneously.

The classic trigger is a shared component library. A change to a Button component in ui-lib needs to be reflected and tested in web-app and admin-portal in the same commit. This avoids versioning hell and integration failures that plague multi-repo setups (polyrepo).

The trade-off is complexity. Without tooling, a monorepo is unworkable. Running npm install at the root is slow. Running tests for every project on every commit is a CI bottleneck. You can't just git clone and npm start anymore.

In an interview, frame the choice as a response to specific scaling pains. Don't just list pros and cons. Start with the problem: "As the number of interdependent frontend applications grew, we spent more time managing package versions and coordinating breaking changes across repos than building features. A monorepo solved this by enabling atomic commits."

The trap: Over-fragmentation. Don't create a hundred tiny libraries for every single function. A good library is a cohesive unit with a clear purpose. Too many internal packages create dependency spaghetti and configuration overhead, negating the benefits.

How to choose your tooling

Your choice of tool depends on your primary goal. Are you publishing packages, or building integrated applications?

Lerna is the classic choice for managing and publishing multiple packages to a registry like npm. Its main job is to orchestrate npm publish and manage versioning across packages. It simplifies running scripts across your projects but offers little for build optimization. It's often paired with another tool like Turborepo or Nx for caching.

Nx is a full-stack build system designed for developing applications within a monorepo. It doesn't just run scripts; it understands your code. By building a dependency graph, it can run tasks in parallel, cache results, and only re-run tasks on code that was actually affected by a change.

For most frontend system design interviews focusing on large applications, Nx is the more relevant and powerful story. It directly addresses the performance and scale questions you will face.

The core problem: Wasted computation

Imagine a monorepo with 5 applications and 30 shared libraries. A developer changes one line of CSS in a single component.

A naive CI pipeline would rebuild and re-test everything. This could take 30-40 minutes. This is the central problem monorepo tooling must solve. You cannot afford to re-compute results for code that hasn't changed.

The goal is to run builds, tests, and linters only for the projects directly or indirectly affected by the code change.

How Nx solves this with a dependency graph

Nx scans your import statements and package.json files to build a dependency graph of the entire workspace. It knows that web-app depends on ui-components, and ui-components depends on shared-utils.

With this graph, Nx provides "affected" commands. If you change a file in shared-utils, running nx affected:test will test shared-utils, ui-components, data-access, web-app, and admin-portal—and nothing else.

This is powerful, but the real optimization is caching. Nx hashes the files of a project and its dependencies. When it runs a task (like build web-app), it stores the output (the dist folder) and the terminal output in a cache, keyed by the hash.

The next time you run build web-app with the same hash, Nx skips the work entirely and restores the files and logs from the cache instantly. This works locally and can be shared across your team and CI with Nx Cloud.

This is your answer to "How would you optimize build times in a large monorepo?". You say: "First, we only run tasks on what's affected by a change. Second, we use computation caching to ensure we never run the same computation twice. A tool like Nx does this by analyzing the project's dependency graph."

What a configuration looks like

You configure Nx through nx.json at the root and a project.json for each project.

The nx.json file defines caching behavior for tasks (called "targets"). Here, we tell Nx that any build target can be cached. We define what files contribute to the cache key (inputs) and what files should be stored in the cache (outputs).

// nx.json
{
  "targetDefaults": {
    "build": {
      "cache": true,
      "inputs": ["production", "^production"],
      "outputs": ["{projectRoot}/dist", "{projectRoot}/.next"]
    },
    "test": {
      "cache": true,
      "inputs": ["default", "^default"],
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"]
    }
  },
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
      "default",
      "!{projectRoot}/**/*.spec.ts"
    ]
  }
}

The ^production syntax in inputs means "include the production inputs of all dependencies". This is how the graph is used for caching. A change in a dependency changes its hash, which invalidates the cache for all upstream projects.

A project.json file defines the tasks for a specific app or library.

// apps/web-app/project.json
{
  "name": "web-app",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "projectType": "application",
  "sourceRoot": "apps/web-app/src",
  "targets": {
    "build": {
      "executor": "@nx/next:build",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/apps/web-app"
      }
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"]
    }
  },
  "implicitDependencies": ["api-service"]
}

The trap: Incorrect cache configuration. If your outputs array doesn't include all files a task generates, or your inputs array misses a file that influences the output, you will get stale cache hits. This leads to "it works on my machine" bugs that are hard to track down. Always be precise with inputs and outputs.

Try it

In a new folder, run npx create-nx-workspace@latest. Choose a setup with one application and one library. Make a change to a file in the library. Run nx affected:build. Observe that both the library and the application are rebuilt. Run the command again immediately. Observe that it reads from the cache and completes in milliseconds.

Next: Atomic Design for Component Libraries

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Module Resolution and Hot Module Replacement

Next

Atomic Design for Component Libraries