Turborepo 2.x: Fast Monorepo Builds With Remote Caching

Turborepo's task graph and remote cache cut monorepo build times dramatically - here is how to set it up with pnpm workspaces, Docker, and self-hosted caching.

Mahmudul Haque Qudrati — CEO & ML Engineer at Pristren

Mahmudul Haque Qudrati

CEO & ML Engineer

April 20, 2026
7 min read
Turborepo 2.x: Fast Monorepo Builds With Remote Caching

Why Turborepo?

One AI engineering post, weekly

LLM benchmarks, prompt techniques, and token-cost breakdowns — not another AI news roundup.

Running pnpm build in a monorepo with 20 packages rebuilds everything every time. Turborepo understands your task dependency graph, caches outputs by input hash, and skips tasks whose inputs have not changed - locally and in CI.

Initial Setup

bash
pnpm add -D turbo -w   # -w installs to workspace root

# Or scaffold a new monorepo
npx create-turbo@latest
json
// turbo.json (root)
{
  "$schema": "https://turbo.build/schema.json",
  "tasks": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "dist/**"]
    },
    "lint": {
      "dependsOn": ["^build"]
    },
    "test": {
      "dependsOn": ["^build"],
      "outputs": ["coverage/**"]
    },
    "dev": {
      "cache": false,
      "persistent": true
    }
  }
}

The "^build" syntax means "run build in all packages this package depends on first."

Team workspace

Ship faster with chat, meetings, and projects in one place — Zlyqor.

Start free

Task Graph in Practice

Given a monorepo with web depending on ui and utils:

snippet
apps/web → packages/ui → packages/utils

Running turbo build automatically:

  1. Builds utils first
  2. Builds ui (can now resolve utils)
  3. Builds web (can now resolve ui and utils)

All independent packages build in parallel.

Remote Cache

The remote cache stores task outputs on a server. When a CI run hits the same input hash, it downloads the cached output instead of running the task.

Vercel Remote Cache (free with Vercel account):

bash
npx turbo login
npx turbo link

Self-hosted with Ducktape:

bash
# Deploy Ducktape (open-source Turborepo remote cache)
docker run -p 3000:3000 ghcr.io/ducktape/ducktape:latest
bash
# Use in CI
TURBO_API=http://your-cache-server:3000 TURBO_TOKEN=your-token TURBO_TEAM=your-team turbo build

Pruning for Docker Layers

turbo prune creates a minimal subset of your monorepo containing only the packages needed for a specific app - ideal for Docker:

dockerfile
FROM node:22-alpine AS pruner
WORKDIR /app
RUN pnpm add -g turbo
COPY . .
RUN turbo prune web --docker

FROM node:22-alpine AS installer
WORKDIR /app
COPY --from=pruner /app/out/json/ .
COPY --from=pruner /app/out/pnpm-lock.yaml ./pnpm-lock.yaml
RUN pnpm install --frozen-lockfile

FROM node:22-alpine AS builder
WORKDIR /app
COPY --from=installer /app .
COPY --from=pruner /app/out/full/ .
RUN turbo build --filter=web

FROM node:22-alpine AS runner
COPY --from=builder /app/apps/web/.next/standalone ./
CMD ["node", "server.js"]

Filtering for Affected Packages

Only build packages affected by changes on the current branch:

bash
# Build only changed packages and their dependents
turbo build --filter="...[origin/main]"

# Build a specific app and all its dependencies
turbo build --filter=web...

Turborepo vs Nx

FeatureTurborepoNx
Config complexitySimple JSONMore complex
Plugin ecosystemSmallerLarger
Code generationNoYes
Affected detectionGit-basedGit + dep graph
Remote cacheVercel or self-hostedNx Cloud or self-hosted

Turborepo is better for teams that want minimal config and are already on pnpm workspaces. Nx is better for large enterprise monorepos that need code generation and extensive scaffolding.

References: Turborepo · GitHub · remote caching

#turborepo#monorepo#caching#ci/cd#pnpm

// discussion

Comments

0/4000
Mahmudul Haque Qudrati — CEO & ML Engineer at Pristren

Mahmudul Haque Qudrati

CEO & ML Engineer

Visionary technologist, software engineer, and machine learning specialist. Founder and CEO of Pristren, directing engineering teams that ship production-grade AI/ML pipelines, mission-critical full-stack applications, and developer tooling. Creator of Zlyqor, the unified team workspace platform. Author of 540+ technical guides and benchmark research reports on large language models, agentic workflows, Model Context Protocol (MCP), and modern web stacks.

PristrenZlyqor