惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
阮一峰的网络日志
阮一峰的网络日志
T
Tailwind CSS Blog
博客园 - 【当耐特】
量子位
博客园 - 叶小钗
有赞技术团队
有赞技术团队
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
博客园 - 司徒正美
爱范儿
爱范儿
美团技术团队
小众软件
小众软件
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
罗磊的独立博客
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
Hugging Face - Blog
Hugging Face - Blog
I
InfoQ
D
DataBreaches.Net
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Scaling Monorepos with Turborepo
Subhan Farra · 2026-05-26 · via DEV Community

Subhan Farrakh

Originally published on subhanfarrakh.com/blog

Why Monorepos Break Down Without Tooling

A monorepo starts simple: two packages, fast builds, easy sharing. Then it grows. Six packages, twelve packages. Suddenly npm run build in the root takes four minutes because it rebuilds every package every time, even the ones that haven't changed.

This is the problem Turborepo was built to solve.

The Task Graph

Turborepo models your monorepo as a task graph — a directed acyclic graph where nodes are tasks and edges are dependencies between them.

{
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "dist/**"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    },
    "lint": {
      "dependsOn": ["^lint"]
    }
  }
}

Enter fullscreen mode Exit fullscreen mode

The ^ prefix means "run this task in all dependencies first." So when you run turbo build in a monorepo where web depends on ui and utils, Turbo:

  1. Builds utils (no dependencies)
  2. Builds ui (depends on utils)
  3. Builds web (depends on both)

And it does this with maximum parallelism — tasks that don't depend on each other run concurrently.

Caching: The Real Win

The graph is clever. The cache is transformative.

Turbo hashes the inputs of every task: source files, environment variables, lock files, task configuration. If the hash matches a previous run, Turbo replays the output instantly — it doesn't run the task at all.

# First run: builds everything (4m 12s)
turbo build

# Second run, nothing changed: replays from cache (1.3s)
turbo build
>>> FULL TURBO (cache hit)

Enter fullscreen mode Exit fullscreen mode

Remote caching extends this to your entire team and CI. Once a teammate builds a package, everyone else gets the cached output. A fresh CI run on a PR that only touches web doesn't rebuild ui — it fetches the cached artifact from Vercel Remote Cache or your own S3 bucket.

Workspace Structure That Scales

The package structure that works well in practice:

apps/
  web/          # User-facing app (Next.js, Astro, etc.)
  cms/          # Admin/CMS app
packages/
  ui/           # Shared React components
  typescript-config/  # Shared tsconfig bases
  eslint-config/      # Shared ESLint configs

Enter fullscreen mode Exit fullscreen mode

Packages in packages/ should be internal-only by default ("private": true). They're not published to npm; they're consumed directly by apps via workspace references:

{
  "dependencies": {
    "@repo/ui": "workspace:*"
  }
}

Enter fullscreen mode Exit fullscreen mode

Common Mistakes

Putting too much in one package. If a package has 50 components and you change one, the entire package's cache is invalidated. Split by domain, not by size.

Not specifying outputs. Without outputs defined, Turbo can't cache build artifacts. Every task that produces files needs an outputs entry.

Using dependsOn: ["build"] instead of ["^build"]. The former depends on the build task in the same package. The latter depends on build in all dependencies — which is almost always what you want.

The Pipeline Mental Model

Think of your monorepo tasks like a pipeline in a factory. Raw inputs (source code) flow through stages (lint → type-check → build → test) with shared components built once and reused everywhere. Turborepo's job is to run that pipeline as fast as physics allows, skipping any stage where the inputs haven't changed.

Once you internalize this mental model, the configuration becomes intuitive and debugging cache misses becomes methodical.