Remote caching shares build results across your team and CI so you don't repeat work. You can use Nx Cloud for a fully managed solution or build your own self-hosted server using the OpenAPI specification below.
Get started with Nx CloudFully managed remote caching with Nx Cloud
For single-tenant, dedicated-region, or on-prem hosting, see Nx Enterprise.
Build your own caching server
Section titled “Build your own caching server”You can build your own caching server using the OpenAPI specification below and tailor it to your needs. The server manages all aspects of the remote cache, including storage, retrieval, and authentication.
Implementation is up to you, but the server must adhere to the OpenAPI specification below to ensure compatibility with Nx caching mechanism. The endpoints transfer tar archives as binary data. Note that while the underlying data format may change in future Nx versions, the OpenAPI specification should remain stable.
You can implement your server in any programming language or framework, as long as it adheres to the OpenAPI spec.
Open API specification
Section titled “Open API specification”{ "openapi": "3.0.0", "info": { "title": "Nx custom remote cache specification.", "description": "Nx is an AI-first monorepo platform that connects everything from your editor to CI. Helping you deliver fast, without breaking things.", "version": "1.0.0" }, "paths": { "/v1/cache/{hash}": { "put": { "description": "Upload a task output", "operationId": "put", "security": [ { "bearerToken": [] } ], "responses": { "200": { "description": "Successfully uploaded the output" }, "401": { "description": "Missing or invalid authentication token.", "content": { "text/plain": { "schema": { "type": "string", "description": "Error message provided to the Nx CLI user" } } } }, "403": { "description": "Access forbidden. (e.g. read-only token used to write)", "content": { "text/plain": { "schema": { "type": "string", "description": "Error message provided to the Nx CLI user" } } } }, "409": { "description": "Cannot override an existing record" } }, "parameters": [ { "in": "header", "description": "The file size in bytes. Servers must compare the number of body bytes actually received against this value and reject the upload if fewer arrive. See 'Handling incomplete uploads'.", "required": true, "schema": { "type": "number" }, "name": "Content-Length" }, { "name": "hash", "description": "The task hash corresponding to the uploaded task output", "in": "path", "required": true, "schema": { "type": "string" } } ], "requestBody": { "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary" } } } } }, "get": { "description": "Download a task output", "operationId": "get", "security": [ { "bearerToken": [] } ], "responses": { "200": { "description": "Successfully retrieved cache artifact", "content": { "application/octet-stream": { "schema": { "type": "string", "format": "binary", "description": "An octet stream with the content." } } } }, "403": { "description": "Access forbidden", "content": { "text/plain": { "schema": { "type": "string", "description": "Error message provided to the Nx CLI user" } } } }, "404": { "description": "The record was not found" } }, "parameters": [ { "name": "hash", "in": "path", "required": true, "schema": { "type": "string" } } ] } } }, "components": { "securitySchemes": { "bearerToken": { "type": "http", "description": "Auth mechanism", "scheme": "bearer" } } }}Handling incomplete uploads
Section titled “Handling incomplete uploads”A PUT can stop early. The client times out, CI cancels the job, or the network drops mid-body. Your server must never leave a hash readable in that case. A later GET that returns a truncated tarball is worse than a cache miss. Nx rebuilds the task locally, but it can't replace the damaged entry, because the server answers later uploads of that hash with 409 Conflict.
Validate Content-Length before you commit the upload. The header is required, and Nx always sends the full artifact size. Compare it against the bytes you actually received and reject the upload if they differ. Return the entry only once the complete body has arrived.
Whether this is a risk for you depends on when the body is read:
- If the whole body is read before your handler runs, a truncated request fails before your code sees it, so nothing gets persisted.
express.raw(), Spring's@RequestBody byte[], theBytesextractors in axum and actix-web, and Puma (for Rack apps) all work this way. - If your handler reads the body itself, you must check the error from that read.
io.Copy(dst, r.Body)in Go,Request.Bodyin ASP.NET Core,await request.body()andrequest.stream()in Starlette, andreq.pipe(...)in Node all read inside your handler. The truncation surfaces there as a returned error or exception, and ignoring it can leave a partial artifact on disk.
Two ordering details matter more than the language you chose:
- Write the artifact durably before you publish the entry. Stream to a temporary path and rename into place only after the body is complete and its length checked, or use an object store whose single-request
PUTis atomic. Reserving the hash first and filling it in afterwards is the pattern that produces an entry with no artifacts. - For filesystem-backed servers, the artifact path is the index. There is no separate database row to guard, so creating the final file and writing into it incrementally is itself the bug.
If you sit behind a reverse proxy, check its buffering. nginx's proxy_request_buffering is on by default, so it buffers the full body and shields your upstream entirely. Large-upload setups often turn it off, which removes that protection.
Usage notes
Section titled “Usage notes”To use your custom caching server, set the NX_SELF_HOSTED_REMOTE_CACHE_SERVER environment variable. The following environment variables also affect behavior:
NX_SELF_HOSTED_REMOTE_CACHE_ACCESS_TOKEN: The authentication token to access the cache server.NODE_TLS_REJECT_UNAUTHORIZED: Set to0to disable TLS certificate validation.NX_SELF_HOSTED_REMOTE_CACHE_NO_TIMEOUTS: Set to any value to wait indefinitely for the cache server instead of timing out. Only useful if legitimate transfers exceed the built-in budgets. A server that accepts a connection and never replies will then hang the run instead of falling back to a local rebuild.
Nx applies a 10 second connect timeout, a 120 second download timeout, and a 10 minute upload timeout. The download timeout bounds how long Nx waits for the server's next chunk of the response, and it resets each time a chunk arrives, so it detects a stalled server rather than capping artifact size. A large artifact that downloads steadily never trips it. Before the first byte there is nothing to reset, so the same budget doubles as a deadline on how long your server can take to start responding. Set NX_SELF_HOSTED_REMOTE_CACHE_NO_TIMEOUTS if yours builds or fetches artifacts on demand and needs longer.
A cache request that fails or times out is not fatal. Nx warns, rebuilds the task locally, and the run continues. That covers a connection Nx cannot make, a server that stalls mid-response, and a 408, 429 or 5xx reply, since a later run may well succeed. A rate limit in front of your cache server is the common case for the 429. Nx fetches as many missed hashes at once as --parallel allows, up to 16, so lowering --parallel reduces the request rate.
Nx treats some 4xx replies as normal answers:
404on aGETis a cache miss. Nx runs the task and uploads the result.403on aPUTmeans the server won't accept writes, for example from a read-only token. Nx skips the upload.409on aPUTmeans the hash is already stored. Nx skips the upload.
These still stop the run, because no retry fixes them:
- A
401, which means the server rejected the token. - Any other
4xx, such as a404on aPUT, which means the endpoint is misconfigured. - An artifact that tries to write outside the cache directory.
- A local cache directory that Nx can't write to, such as a full disk.
Migrating from custom tasks runners
Section titled “Migrating from custom tasks runners”You might have used Nx now-deprecated custom task runners API in these scenarios:
- To implement custom self-hosted caching, follow the OpenAPI spec, or switch to Nx Cloud
- To inject custom behavior before and after running tasks: use our new API with dedicated pre and post hooks
To learn more about migrating from custom task runners, please refer to this detailed guide.
Looking for conformance or code owners?
Section titled “Looking for conformance or code owners?”If you previously used Nx Powerpack for conformance rules or code ownership, the @nx/conformance and @nx/owners plugins are now open source and MIT licensed, and don't need an Nx key or license. See:
- Conformance — write and enforce language-agnostic rules across your workspace
- Owners — define code ownership at the project level and auto-generate CODEOWNERS files