The interview problem

Practice prompt

Design a shared build artifact cache for five hundred developers and a continuous integration fleet. Builds contain many independent compilation actions. Reuse results across machines without returning a binary built with the wrong inputs or accepting poisoned results from an untrusted pull request. Explain keys, publication, eviction and behavior during an outage.

Original system-design practice, not a reported company interview. Workload figures and the proposed protocol are hypothetical. Primary documentation retrieved September 27, 2026; publication date not stated; interview date not applicable.

1. Define correctness before hit rate

A cache hit must represent the requested action under the declared execution contract. Equal source filenames are insufficient. Include input contents, toolchain identity, command arguments, relevant environment, target platform and output declaration. State which actions are eligible: start with deterministic compilation in a controlled environment. Network-dependent generators, time-sensitive tests and signing operations need separate policies.

The cache is an optimization, not the release artifact archive. Evicted entries can be recomputed from retained source and dependencies. Release binaries, provenance and retention obligations belong in a durable release system. A cache outage may slow a build but must not silently switch its toolchain or weaken verification.

Separate three claims: bytes match their digest, a trusted worker associated those bytes with this action, and execution actually used the declared inputs. A content hash proves the first under the chosen hash assumptions. It does not independently prove the other two.

2. Separate result lookup from byte storage

build graph → canonical action description → action digest
                                                ↓
                              authorized result lookup
                              ↙ hit              ↘ miss
                   output manifest          isolated execution
                         ↓                         ↓
                content blob store ← verified output upload
                         ↓                         ↓
                local materialization     publish result mapping

Bazel's remote-cache documentation distinguishes an action-result mapping from content-addressed output storage. It also warns about undeclared tools, changing inputs and writer access. Use those as baseline concerns; the stronger publication and isolation choices below are an original design proposal, not a claim about every Bazel backend.

Expose conceptual operations for result lookup, missing-blob discovery, blob upload and result publication. Authenticate each operation and authorize both namespace and operation type. A developer can read approved results while only controlled builders publish into a release-trusted namespace. Untrusted builds use a separate writable namespace and cannot promote their own outputs.

Partition result metadata by a digest prefix within an authorization namespace. Store immutable blobs in scalable object storage with regional read caches. Dedupe within a trust boundary first: a global digest must not become an authorization token that lets someone retrieve another project's binary by knowing its hash.

3. Work through an incorrect hit

Consider two machines with identical source digest S and command cc -O2 input.c. Machine A resolves cc to toolchain T1; machine B resolves it to T2. A key computed only from S and the command is equal on both machines. After A publishes its result, B receives T1 output although its requested environment requires T2. This is a missing dependency, not a cryptographic collision.

In the proposed key, include a canonical input-tree digest, command and argument sequence, permitted environment, toolchain package digest, execution-platform identity and declared output paths. An input tree records normalized relative paths, file digests, executable bits and supported symlink semantics. Use a versioned, unambiguous serialization with field lengths or a defined structured encoding; naïvely concatenating strings can produce ambiguous descriptions.

A version label such as “compiler 12” is weaker than immutable identity when installations can differ. Capture libraries, linker and SDK dependencies too. Merely hashing the compiler executable leaves its external configuration and dynamically loaded dependencies uncontrolled. A container image can help identify an environment, but host mounts, kernel-sensitive behavior and network dependencies still require an explicit execution contract.

Hash and execute from the same immutable workspace snapshot. Otherwise a file can change after hashing and before compilation, causing output from new bytes to be published under an old key. Reject unsupported environmental dependencies or mark the action uncacheable; do not hide nondeterminism by assigning arbitrary freshness lifetimes.

4. Publish only complete results

A worker uploads each output into staging, verifies its digest and length, and finalizes the immutable blob. It then publishes a result manifest referencing all required blobs. The service checks publisher authority and availability of the referenced objects. A crash before publishing leaves reclaimable orphan blobs; a crash after publishing leaves a usable result. The mapping must never intentionally point at a half-uploaded object.

Readers validate returned blobs and materialize into a temporary directory before atomically exposing a complete action result locally. Reject path traversal and unsafe output symlink targets. A missing or corrupt blob turns the entire action lookup into a miss, with bounded retries and an integrity alert. Never combine an old output file with a partial new result simply to finish a download.

Two workers may compute the same action concurrently. Duplicate execution is acceptable; a lease can reduce it but is not required for correctness. Use conditional publication. If existing and new manifests disagree for the same action, mark the action mapping ineligible for subsequent hits, quarantine both conflicting results, and investigate undeclared inputs or nondeterminism instead of choosing whichever response arrives last. A deterministic action should agree, but cached success does not prove that assumption.

Availability checks alone do not prevent garbage collection immediately afterward. Pin objects during publication and reads, or use a documented grace period with read retries. Since this is a recomputable cache, a residual eviction race can safely degrade to a miss. It must not degrade to accepting an incomplete result.

5. Calculate savings and bottlenecks

Assume one million action lookups per day, an 80% usable hit rate and twenty CPU-seconds per action if executed. Without caching, execution consumes twenty million CPU-seconds, about 5,555.6 CPU-hours. With caching, two hundred thousand misses consume four million CPU-seconds, about 1,111.1 CPU-hours. The ideal execution saving is 4,444.4 CPU-hours/day, before hashing, transfer, verification and cache-service overhead.

If each hit downloads an average of 2 MB decimal, eight hundred thousand hits transfer 1.6 TB/day, an average of 18.52 MB/s over twenty-four hours. A tenfold traffic peak requires roughly 185.2 MB/s under the same size distribution. Large link outputs and synchronized CI starts can make byte peaks much worse than the mean action count suggests.

If each miss produces 2 MB of unique retained output, writes add 400 GB/day. A seven-day window holds 2.8 TB logically, or 5.6 TB with two physical copies, excluding metadata and overhead. Real storage depends on deduplication and eviction; seven-day age retention is not a hard capacity cap during a workload spike. Enforce a separate byte budget.

Do not translate 80% action hits into an 80% shorter build. In a simplified critical path with ten sequential twenty-second actions, eight hits taking one second each and two misses taking twenty seconds each reduce that path from 200 to 48 seconds, a 4.17-fold speedup. Hits on actions outside the critical path may save compute without changing the wall-clock completion time.

6. Treat publication as a trust decision

A malicious writer can upload malicious bytes with their correct digest and then associate them with a desirable action key. Client digest checking will pass. Prevent that by restricting publication authority, separating untrusted jobs and recording worker identity, execution policy and input identity with the result. Signed metadata identifies its signer; it does not make a compromised signer truthful.

Run periodic independent rebuilds of sampled eligible actions and compare outputs under an agreed reproducibility contract. Investigate differences instead of automatically normalizing away meaningful changes. Sampling is detection evidence, not proof that every cached result is correct. Critical releases may require dedicated trusted rebuilding or a stricter provenance policy.

Keep credentials out of arguments, captured environment and logs whenever possible. Access-controlled blobs can still contain embedded secrets or proprietary source maps. Define artifact sensitivity, read permissions and deletion behavior. Revoking a writer prevents future publication; handling its already published results requires an explicit trust-epoch change or targeted invalidation and a controlled rebuild plan. Clients must enforce that trust policy for locally reused results too; changing only the remote lookup namespace does not invalidate binaries already on disk. Results already consumed cannot be retroactively unexecuted.

7. Fail safely under load and partial failure

Bound lookup deadlines and open a circuit breaker when the cache is unhealthy. Fall back to local execution only where capacity and execution policy permit. A fleet-wide fallback can multiply compute demand: with the example's 80% hits, full recomputation increases execution demand from two hundred thousand to one million actions, fivefold. Queue lower-priority jobs rather than overwhelming builders.

Missing regional replicas are misses, not evidence an action never existed. Replicate finalized blobs before advertising a local hit, or route downloads to a known available region within the latency budget. Negative lookup caching needs short bounds because a peer may publish immediately afterward. Do not cache transient infrastructure errors as durable build failures.

Test an input mutation during execution, two distinct toolchains, a forged action mapping, interrupted upload, missing blob, GC during download, duplicate workers and two different results for one key. Track usable hits after full verification, bytes transferred, critical-path savings, conflicting manifests, rebuild mismatches and fallback queue age. A metadata hit that cannot supply its outputs is not a successful hit.

8. Trade-offs and follow-ups

Stronger execution isolation costs setup time but improves confidence in reuse. Fine-grained actions improve reuse while increasing metadata traffic. Regional caches reduce latency while adding replica and eviction complexity. Read-only developer access limits poisoning exposure but reduces warming opportunities. Coordinate these choices with measured build profiles, rather than maximizing the cache-hit percentage alone.

Follow-ups: How would you support cross-compilation? Which tests may reuse a cached result? How do branch changes affect action keys? Can results be shared across repositories with different access policies? What if the toolchain is compromised? How would you diagnose a low hit rate without logging secrets? When does downloading a large output cost more than rebuilding it?

9. Self-review rubric

  • Define eligible actions and the exact meaning of a correct hit.
  • Include toolchain, platform and immutable inputs in an unambiguous key.
  • Separate byte integrity from trusted execution provenance.
  • Publish complete results and handle conflicting outputs explicitly.
  • Make eviction, partial download and outage degrade safely.
  • Calculate CPU, storage, bandwidth and critical-path effects separately.
  • Test missing dependencies and malicious mappings, not just cache availability.

Sources and related practice

Bazel: Remote Caching, publication date not stated; retrieved September 27, 2026. Primary background for action caching, content-addressed outputs and documented correctness concerns. The workload, security boundaries, publication protocol and worked calculations are original practice design.

Continue with object garbage collection, distributed caches and checkpoint storage.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.