Monorepo Build Cache Optimization Guide
Diagnose slow monorepo builds and create a practical optimization plan for local developer workflows, CI pipelines, caching, and dependency boundaries.
Prompt Template
You are a senior developer experience engineer. Audit a monorepo build setup and recommend a build cache optimization plan. Monorepo stack: [Turborepo, Nx, Bazel, pnpm workspaces, Yarn workspaces, npm workspaces, custom] Languages/frameworks: [TypeScript, React, Next.js, Node, Go, Python, etc.] Package count: [number of apps/packages] Current build/test commands: [commands] CI provider: [GitHub Actions, GitLab CI, CircleCI, Buildkite, etc.] Current pain points: [slow builds, flaky cache, repeated tests, dependency sprawl, cold installs] Cache setup: [local cache, remote cache, node_modules cache, build artifacts] Recent timing data: [build minutes, test minutes, install minutes] Constraints: [security, no SaaS cache, self-hosted runners, limited CI minutes] Provide: 1. Likely bottlenecks and what evidence to collect. 2. Build graph audit checklist for package boundaries and implicit dependencies. 3. Cache key strategy for dependencies, build outputs, tests, linting, and generated files. 4. CI workflow changes with example job structure and parallelization plan. 5. Local developer workflow improvements for affected-package commands and watch mode. 6. Remote cache recommendation, including security and secret-handling concerns. 7. Measurement plan with baseline, target, and instrumentation. 8. Rollout plan that avoids breaking releases. 9. Red flags that indicate cache poisoning, stale artifacts, or hidden dependency issues. Keep recommendations framework-aware and practical; do not suggest rewriting the whole repo unless evidence supports it.
Example Output
Diagnosis
The biggest wins are likely in install caching and affected-package execution. Current CI runs build, lint, and test across all 42 packages on every pull request, even when only one app changes.
Cache Strategy
- Dependency cache key: lockfile hash + Node version + package manager version.
- Build output cache: include source files, tsconfig, env schema, codegen inputs, and package dependency graph.
- Do not cache .env files, secrets, or generated artifacts that include credentials.
CI Shape
1. install job restores pnpm store cache.
2. affected graph job calculates changed packages against main.
3. parallel jobs run lint/test/build only for affected packages plus dependents.
4. final verification runs full build nightly or before release tags.
Target
Reduce average PR feedback from 18 minutes to under 7 minutes while keeping a nightly full build as a safety net.
Tips for Best Results
- 💡Provide real timing data if you have it; cache advice is much better when the model can rank bottlenecks.
- 💡Ask for cache invalidation rules explicitly so speed does not come at the cost of stale builds.
- 💡Include CI provider and package manager because cache syntax and best practices differ a lot.
- 💡Roll out in stages: measure first, cache dependencies, then cache build outputs, then parallelize.
Related Prompts
Technical Documentation Writer
Generate clear, comprehensive technical documentation for APIs, functions, systems, or libraries.
Code Review Assistant
Get a thorough, senior-level code review with actionable feedback on quality, security, performance, and best practices.
Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.