Implementing Remote Caching in Turborepo for Distributed CI/CD
Learn how to implement Remote Caching in Turborepo to eliminate redundant builds across CI/CD pipelines and distributed development teams.
19 Jan 2026, 03:32 UTC

The Redundant Build Problem
In large monorepos, developers and CI runners often spend significant time rebuilding the same packages. Even with local caching, a CI runner starts with a clean slate, meaning every commit triggers a full rebuild of unchanged packages. This redundancy slows down deployment cycles and increases compute costs.
The solution is Remote Caching. By moving the cache from a local .turbo folder to a shared remote store, any machine that has already executed a specific task can upload the resulting artifacts. Subsequent requests for that same task—whether from a teammate's laptop or a production pipeline—can simply download the artifacts instead of re-running the build.
Prerequisites
- A Turborepo project with a valid
turbo.jsonconfiguration. - A remote cache provider (such as Vercel Remote Cache or a self-hosted compatible server).
- An authentication token and team ID provided by your cache host.
- Node.js environment where the
turboCLI is installed globally or as a dev dependency.
Configuring the Pipeline for Cache Integrity
Remote caching only works if Turbo can accurately determine if a task's inputs have changed. If your turbo.json is missing output definitions, the remote store will record that a task "finished," but it won't have any files to give to the next user, resulting in a broken build.
Defining Inputs and Outputs
Update your turbo.json to explicitly map what goes into a task and what comes out. This ensures the cache key is deterministic.
{
"pipeline": {
"build": {
"dependsOn": ["^build"],
"inputs": ["src/**", "package.json", "tsconfig.json"],
"outputs": ["dist/**", ".next/**", "out/**"]
},
"test": {
"inputs": ["src/**", "test/**"],
"outputs": []
}
}
}
Handling Environment Variables
If your build depends on environment variables (e.g., API_URL), Turbo must include those variables in the hash calculation. If you don't, two different environments might share the same cache entry despite having different configurations, leading to "poisoned" caches.
Add required variables to the globalPassThroughEnv or task-specific env array in turbo.json to ensure they are tracked.
Connecting to the Remote Store
Remote caching is activated via environment variables. You do not need to change your code; you only need to configure the shell or the CI provider.
Local Development Setup
To enable remote caching on your local machine, run the following command in your terminal (replace placeholders with your actual credentials):
# For macOS/Linux
export TURBO_TOKEN=your_secret_token
export TURBO_TEAM=your_team_id
# For Windows (PowerShell)
$env:TURBO_TOKEN="your_secret_token"
$env:TURBO_TEAM="your_team_id"
CI/CD Integration
In your CI provider (e.g., GitHub Actions, GitLab CI), add TURBO_TOKEN and TURBO_TEAM as encrypted secrets. This allows the runner to authenticate with the remote store during the build step.
Verifying Cache Hits
To confirm that remote caching is functioning, execute a build task and observe the terminal output.
- Run
npx turbo run buildon Machine A. You should seecache missfor the first run. - Run
npx turbo run buildagain on Machine A. You should seeFULL CACHE(local hit). - Run
npx turbo run buildon Machine B (or a CI runner). You should seeREMOTE CACHE.
Diagnostic Comparison
| Label | Meaning | Performance Impact |
|---|---|---|
cache miss |
Task executed from scratch. | Slowest (Full compute) |
FULL CACHE |
Artifacts found in local .turbo folder. |
Fastest (Disk I/O) |
REMOTE CACHE |
Artifacts downloaded from remote store. | Fast (Network I/O) |
Limitations and Risks
- Network Latency: If your build artifacts (e.g.,
distfolders) are several gigabytes in size, the time spent downloading them from the remote cache may exceed the time it takes to simply rebuild them locally. - Cache Poisoning: If
outputsare defined incorrectly, a "successful" build might be cached without the actual files. This causes subsequent runs to skip the build but fail during deployment because the files are missing. - Secret Leakage: Ensure
TURBO_TOKENis never committed to version control.
Rollback Procedure
If you encounter inconsistent build artifacts or cache poisoning, you can disable remote caching by removing the environment variables from your shell or CI settings:
unset TURBO_TOKEN
unset TURBO_TEAM
To clear the local cache and force a fresh start, delete the .turbo directory in your project root.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.