CI/CD · Ship safely, repeatedly

How does build caching speed up CI and what can go wrong?

MediumcachingperformancebuildsUpdated Oct 2026
Quiz this track

Short answer

Build caching reuses dependencies or compiled outputs when the inputs are unchanged, keyed by lockfiles, toolchain versions and source hashes. Bad keys or poisoned caches can produce incorrect builds, so correctness must come before hit rate.

A good cache key captures everything that affects the output. If the key ignores a compiler version or a lockfile change, the pipeline can restore stale output and pass tests against code that was never actually built.

  • Cache package manager downloads keyed by the lockfile hash
  • Cache compiled outputs keyed by source, toolchain and build flags
  • Use a remote cache shared across runners for large teams
  • Make cache writes from untrusted pull requests unable to poison the main cache
  • Measure hit rate and build time rather than assuming caching helped
yaml
cache:
  key: deps-lock-9f2c1a
  paths:
    - node_modules
    - .cache/turbo
  restore-keys: deps-lock-
A cache is an optimization, not a source of truth. If deleting the cache changes the result, the build has a hidden input or a non-deterministic step that needs fixing.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What belongs in a cache key?
  2. 2How do you stop a fork pull request from poisoning the cache?
  3. 3When should you not cache?
  4. 4How do you debug a cache-related build failure?

Say it in the interview

Build caching reuses work when the inputs are unchanged. I key dependency caches on the lockfile and toolchain, and compiled output on source plus build flags. A shared remote cache helps large teams, but I isolate untrusted pull requests so they cannot write to the trusted cache. Correctness comes first, so if clearing the cache changes the output, the build is not reproducible.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live CI/CD mock interview and get scored feedback on depth, clarity and confidence.