EasyMonorepo📖 Theory Question

How does Turborepo's caching work and what makes it fast?

💡

Hint

Task outputs are hashed by inputs (files + env vars); cache hits skip execution entirely — local and remote caches both supported

Full Answer

Turborepo speeds up monorepo builds through content-addressed caching and parallel execution.

Caching mechanism:

  1. Before running a task, Turbo computes a hash from: source files in the package, env variables listed in turbo.json, the task's dependencies' output hashes.
  2. If a cache entry exists for that hash, Turbo replays the cached output (logs + output files) instead of running the task.
  3. Cache hits are instantaneous — CI re-runs of unchanged packages take milliseconds.
// turbo.json
{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],  // build deps first
      "outputs": ["dist/**"],
      "env": ["NODE_ENV"]       // include in hash
    },
    "test": {
      "dependsOn": ["build"],
      "outputs": []
    }
  }
}

Remote cache — Turborepo can push/pull cache to Vercel Remote Cache or a self-hosted HTTP cache. First CI run populates it; all subsequent machines (and developer laptops) benefit.

More Monorepo Questions

EasyWhat is a monorepo and what are its advantages over a polyrepo setup?EasyHow does Nx differ from Turborepo?EasyWhat are pnpm workspaces and why are they preferred in monorepos?EasyWhat are module boundary rules in Nx and why do they matter?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint