December 1, 2026
7 min read time

Your artifacts want to be cached, not mirrored

For the 20 years that Varnish has been around, performance has always been a core foundation of its value. Reliability, security and observability are not to be ignored, but speed has always had a very direct impact on a company’s bottom line. When we started, websites had to load fast to avoid losing customer engagement, same thing with video streaming with the added complication that network bandwidth is costly, so serving data locally was cheaper for a content provider.

Now, we also live in an era of massive projects with thousands of dependencies that need to be downloaded before a CI/CD runner can start building and deploying, not to mention all those GPUs needing to retrieve large amounts of heavy files before crunching numbers and training the AI/ML models we all rely on. If one is able to reduce the download time of these files, servers can focus their time on compute, rather than on I/O. Resources are more efficiently used, pipelines get shorter, costs go down.

So, how do we get the needed data to the servers that need it as fast as possible? Locality is the way to go so that said data doesn’t need to travel too far, and in this post we are going to explore two ways of doing this: mirroring and caching. I have opinions about both, but I’ll also keep things fairly high-level as this can apply to a vast array of use cases.

Mirroring

If your data is “somewhere” and you need it “somewhere else”, it would make sense to just copy it from the first place to the second one, right?Mirroring-2-1

That’s what mirroring is, and it works well, in theory. Most notably, barring an actual failure of the mirror, your data is now local and the original store can go down without the mirror clients being affected, which is great. But…

The “copy” step is doing a lot of the heavy lifting here. Implementing it will require answering a few hard questions.

What should we copy?

That one is easy: everything. But, are you sure? How big is the original data set? It’s not unusual to deal with S3 stores that weigh hundreds of terabytes or petabytes. All that data needs to be stored, and the more you store, the more it costs. If you use cloud storage, it’s just a matter of throwing money at the problem, but with on-prem storage, you get into “fun” logistics problems like rack space, disk procurement or number of ports on your routers.

In light of this, does it make sense to keep the docker images that are 50 versions behind the latest tag, or data parquet file from 2018 that an intern created for their local tests? And to be clear: I’m not being rhetorical here, those questions are completely valid and need to be answered with knowledge that is unique to each environment and each decision carries weight and responsibility.

How often should we sync?

Chances are, your data isn’t immutable, and new files get added all the time. Be they video assets in AWS S3 for a production, parquet files to a Vast setup for High Frequency Trading data analysis, npm or maven packages to Artifactory, there’s usually new stuff to store all the time. So you need to decide when to push the data to the mirrors. This could be a periodic job, or something that happens at ingestion (AWS S3 can do that automatically for example). Again, this is another decision point which will have impacts further down the line, more on this later.

There’s also a price associated with this decision since you’ll probably pay egress/ingress fees, so the previous point is also relevant here because replication will cost money, even for the data that may not be used in the other regions.

Should the replication be bidirectional?

It’s probably a niche question, but if the mirror can also ingest data, you get to answer the first two questions in the mirror-to-origin direction, plus the interesting logic of conflict resolutions. If you’ve ever had to deal with competing git Pull Requests, you know the can of worms this opens.

What happens if the mirror doesn’t have the data? Or has it, but shouldn’t?

This is the big one! When you mirror, you duplicate your source of truth, and users will rely on it. What should happen if the mirror is out of sync and doesn’t have the data your user seeks? The not-wrong-but-naive answers notably include:

  • Retry later. Nothing you can do, you just have to wait until the synchronization actually happens. Hopefully, it won’t be long now.

  • Try the original store, or maybe another mirror. Linux users from the 2000s know the joy of configuring all the package mirrors to pick the best one, but this highlights the issue: your users need to be aware of the mirrors and how to access them independently.

Of course, a missing file is the easy case: it’s immediately detectable, but sometimes the mirror does have the file, but it’s out-of-date, or the file was pulled from the original store (malicious package, anyone?) and the synchronization hasn’t yanked it from the mirror yet. Those cases are A LOT harder to detect and resolve.

Also, there are extra questions about the time the replication takes. If you have petabytes of files to synchronize, it could probably take a few minutes to complete, and in that time window, is the data consistently usable?

Caching

Now, you are reading a Varnish post from a guy who’s been doing HTTP caching for the past 15 years, so I’m obviously going to be a tiny bit biased, but I’ll still try to be fair.

Our diagram here isn’t going to be different from the first one. Personally, I like to think of caching as “just-in-time” mirroring:

Caching-2-1

Clients reach out to the local service which happily delivers the data from cache if it has it, or goes and downloads it from the origin if it doesn’t.

This means you don’t need to decide what to cache, the user traffic will do it for you, organically. It is absolutely possible to pre-warm the cache if you know what your users will need, but in most cases, it’s not needed.

You’ll also notice that the Local cache box is tinier than the mirror in the first diagram, there’s a meaning to this change. You don’t size a cache based on the total data set, but on the hot set, i.e. what amount of data is necessary at the same time. To go back to the docker image example, you probably only need to cache the latest two versions of an image, as they are the ones that will be used at any given time. As new versions are released, users will migrate to them and stop using the old ones, which brings me to my next point: space management.

With a file system, or redis store, you get in trouble if you fill it up. You won’t be able to write new data until you’ve done some cleaning and deleted some data. With a proper cache, this is handled automatically: Varnish for example will evict content based on popularity, so those old docker images we were talking about will be evicted to make room for new data. This mechanism allows the cache to be contained while maintaining popular content ready to go.

Varnish has some very cool features like clustering/sharding and disk storage that allow you to efficiently grow your cache service horizontally if you wish to, but let’s keep things agnostic for now.

What about latency?

Nothing in this world is free nor magic and you’re probably wondering how the “just-in-time” behavior impacts latency. After all, if the file isn’t in cache, it needs to be fetched from the origin, so the locality is bad, isn’t it?

It’s a very good question, and one that needs to be studied not from the perspective of a single download, but in the context of a larger system. With caching, the first download will indeed pay to get the object in cache, but the following clients will have access to the file immediately. Depending on your cache, you also get a few extra benefits:

  • Request coalescing: multiple clients asking for the same uncached object only trigger one origin fetch

  • Streaming: clients don’t need to wait until the object is fully in cache to start getting data

  • Conditional revalidation: some caches can keep expired objects around, and just revalidates them against the origin, saving bandwidth and time when they need to be refreshed

And consistency?

One of my issues with mirroring was that most of the time, replication systems will just lug files around without semantic understanding. This could mean copying a video manifest before the chunks it references, meaning the system can be in an inconsistent state for a while.

Caching can technically lead to the same issues via overcaching - i.e. the cache keeps around a response past its validity. It’s technically an issue, but it's one that Varnish products negate by injecting that aforementioned semantic understanding into the caching logic. To pick the example of the Virtual Registry, it knows the difference between a Docker image manifest (subject to change, TTL just high enough to benefit from request coalescing) and a Docker image layer (content-addressed, extremely large TTL). This knowledge allows the system to balance reactivity and performance while maintaining correctness.

Which one to pick?

As mentioned, I’m a bit biased here, but I don’t think there’s a systematically better answer. In the contexts I work in most often, like artifact distributions for CI/CD runners or AI/ML training, yes, caching has a clear upper hand, but there are use cases where mirroring may make more sense, such as complex systems with very low connectivity.

And even then, while both concepts essentially alleviate the same problem, nothing prevents you from applying both: you can mirror a subset of your data in one place, cache it into another, or even front your mirror with a cache.

Did I write a full post just to conclude on “it depends™”? Well, yes, absolutely. Of course, I want to see Varnish caching everything, including your rust crates and apk packages, but more importantly than that, I want to make sure that we make conscious technical choices and knowing the difference between two adjacent but different solutions is a big part of this. As we rely more and more on agents to guide our engineering work, I feel it’s important to retain our grasp on the fundamentals.