ci-cdplatform-engineeringcost-optimizationdevops

Build cache cost tradeoff: storage and egress versus compute minutes

A remote build cache turns compute minutes into storage and transfer charges. That trade is usually excellent and occasionally terrible, depending on hit rate, object size, and where the cache lives relative to the runners. Here is the arithmetic.

The C3X Team··7 min read

Quick answer

A remote build cache trades compute minutes for storage, requests, and data transfer. It pays off when the cache hit rate is high and the cache lives in the same region and availability zone as the runners. At a 75 percent hit rate, a cache that cuts a 12 minute build to 3 minutes saves about 9 minutes per run, worth far more than the few cents of storage and transfer. It fails when hit rates fall below roughly 40 percent, when cached objects are large, or when transfer crosses zones or regions.

Caching in CI looks like a pure win. Skip work you already did, ship faster, pay less. In practice it is a trade: you stop paying for compute minutes and start paying for storage, requests, and data transfer, plus the engineering time to keep the cache correct.

The trade is usually strongly positive. It is worth knowing which conditions flip it, because a badly placed cache can cost more than the builds it accelerates.

What each side costs

Side of the tradeUnitTypical figure
Runner computePer minuteAbout 0.008 dollars managed, 0.0013 self-hosted
Cache storagePer GB monthAbout 0.023 dollars standard object storage
Cache requestsPer 1,000About 0.0004 to 0.005 dollars
Same zone transferPer GBTypically free
Cross zone transferPer GBAbout 0.01 dollars each direction
Cross region or internetPer GBAbout 0.02 to 0.09 dollars

The asymmetry is stark. Saving one minute of managed runner time is worth about 0.008 dollars, while transferring a 500 MB cache object across availability zones costs about 0.01 dollars in fees alone. Placement decides whether the trade works.

Work an example

Take a build that runs 12 minutes cold and 3 minutes warm, executed 1,500 times a month on managed runners. Without a cache, that is 18,000 minutes, about 144 dollars. With a 75 percent hit rate, it is 375 cold runs plus 1,125 warm runs, roughly 7,875 minutes, about 63 dollars.

Cache side: say 200 GB stored at 0.023 dollars per GB month is about 4.60 dollars, plus a few dollars of requests. If the cache sits in the same zone as the runners, transfer is free and the net saving is roughly 70 dollars a month, and the developer time saved is worth far more than that.

When the trade goes negative

Put the same cache in a different region from the runners and the picture changes. Fifteen hundred pulls of a 500 MB object at 0.02 dollars per GB is about 15 dollars a month in transfer, which still works, but push the object to 3 GB and it becomes 90 dollars, wiping out the saving while also slowing builds because the download itself takes minutes.

Low hit rates break it differently. Below about 40 percent, most runs pay the download attempt, the upload of a new entry, and the full build anyway. You get storage charges, transfer charges, and no time saved. Egress economics are covered inegress cost optimization.

Hit rate is an engineering problem

Most poor hit rates come from cache keys that are too specific: keying on the full commit SHA means every commit misses. Key on the content that actually determines the output, such as a lockfile hash for dependencies or a source tree hash for compiled artifacts, and provide a restore key chain so a near miss still recovers most of the work.

Measure the rate. Most CI systems report cache hits, and if yours does not, log it. A team that discovers its dependency cache hits 30 percent of the time because the key includes a timestamp can fix it in an afternoon and cut the bill immediately.

Prune aggressively

Caches grow without bound if nothing removes entries. Branch scoped caches are the worst offender, since every deleted branch leaves its entries behind. A terabyte of stale cache is about 23 dollars a month, which is small but pure waste, and it also slows listing operations.

Apply a lifecycle rule that expires objects after 14 to 30 days, and scope caches to the default branch where possible so feature branches read from a shared base rather than writing their own copies.

Size and place the cache deliberately

Two rules cover most cases. First, keep the cache in the same region, and ideally the same availability zone, as the runners, so transfer is free and fast. Second, keep individual objects small enough that restoring is much faster than rebuilding, which usually means under a few hundred megabytes.

Since cache buckets, lifecycle rules, and any accelerator services are defined in Terraform, c3x can price that infrastructure from the plan with no cloud credentials before it is created. Set it against the runner minutes you expect to save and the decision stops being a guess. A well placed, well keyed, pruned cache is one of the best returns available in CI. A cross region cache with a 30 percent hit rate is a bill with no upside.

FAQ

Does a remote build cache actually save money?

Usually yes, by a wide margin. A 12 minute build cut to 3 minutes across 1,500 monthly runs at a 75 percent hit rate drops roughly 18,000 minutes to 7,875, saving about 80 dollars of managed runner time against perhaps 8 dollars of storage and requests. The developer time saved is worth considerably more than the direct infrastructure saving.

When does a build cache cost more than it saves?

When the cache is in a different zone or region than the runners, when cached objects are large, or when the hit rate is low. Fifteen hundred pulls of a 3 GB object across regions at 0.02 dollars per GB is about 90 dollars a month, and below roughly 40 percent hit rate most runs pay for a download attempt, an upload, and the full build anyway.

How do I improve CI cache hit rate?

Fix the cache key. Keying on the full commit SHA guarantees a miss on every commit. Key on the content that determines the output, such as a lockfile hash for dependencies or a source tree hash for compiled artifacts, and supply a restore key chain so a near miss still recovers most of the work. Then measure the rate rather than assuming it.

Where should the build cache live?

In the same region and ideally the same availability zone as the runners, so transfer is free and downloads are fast. Cross zone transfer costs about 0.01 dollars per GB in each direction and cross region or internet transfer runs 0.02 to 0.09 dollars per GB, which at CI volumes can exceed the compute savings entirely.

How should build caches be pruned?

With a lifecycle rule expiring objects after 14 to 30 days, plus scoping caches to the default branch where possible so feature branches read a shared base instead of writing their own entries. Branch scoped caches leak badly because deleted branches leave entries behind, and a terabyte of stale cache is about 23 dollars a month of pure waste.

What to do next

Weigh cache storage against runner minutes with real numbers. C3X prices your Terraform cache infrastructure before it exists. Try the quickstart.

Try C3X on your own Terraform

Free and open source. No API key required. One command to install, one command to estimate.