We Replaced the Download, and the CDN Kept Serving the Old One

We fixed a bug in a Mac download, uploaded the corrected file over the old one, checked the headers, saw the new size, and called it done. For a while after that, people who clicked the download button were still being handed the old, broken file. The server had the right bytes. The headers said the right size. The body that arrived in the browser was the previous file.
This post is about that gap: how a CDN in front of a download folder can keep serving an old file after you replace it, why a HEAD request is not a check, and the small set of habits we now follow every time a downloadable file changes. The bug that made us replace the file was a missing Intel slice in our Happy Tracker Mac app, and we will cover that briefly first, because it is how we found the second problem.
The first bug: an Apple-silicon-only build on a page that promised Intel
The Happy Tracker download page said the Mac app ran on “Apple silicon & Intel”. The zip it served contained a binary with one architecture: arm64. On an Intel Mac it would not start at all. Running the old build under Rosetta’s x86_64 mode on our own machine gave the classic error:
Bad CPU type in executable
The cause was one line in the direct-download build script. A sister app’s script built both slices; this one ran a plain release build, which only produces the architecture of the machine doing the building:
# what the build script ran: one slice, the host's own
swift build -c release
# what it needed to run: both slices, merged into one binary
swift build -c release --arch arm64 --arch x86_64
The shipped binary turned out to be newer than every source file, so a rebuild with both architectures was the same app in behaviour, just with the Intel slice added. We smoke-tested both slices locally, the x86_64 one through Rosetta, zipped the app and uploaded it. We have written about universal binaries in depth elsewhere, so we will leave that part there. The interesting failure came next.
The second bug: the file we replaced did not get replaced
The download folder sits behind the hosting provider’s CDN. Every response from it carries server: hcdn and an x-hcdn-cache-status header. We had never thought about that layer, because for static files that rarely change, a CDN is invisible: it just makes downloads faster.
We overwrote HappyTracker-macOS.zip in place, with the same name. Then we checked it the way most people check a file on a web server:
# HEAD: what the edge says about the file
curl -sI https://api-tracker.happycoders.in/downloads/HappyTracker-macOS.zip \
| grep -iE '^(content-length|last-modified|etag|x-hcdn-cache-status)'
# GET: what the edge actually hands a browser
curl -s https://api-tracker.happycoders.in/downloads/HappyTracker-macOS.zip -o got.zip
shasum -a 256 got.zip
ls -l got.zip
The HEAD response looked fresh. The content length matched the new universal zip, which is noticeably larger than the arm64-only one (about 2.2 MB against about 1.7 MB). If we had stopped there, we would have told everyone the fix was live.
We did not stop there, because the only test that matters for a download is downloading it. The GET body that came back was the old file. It was the arm64-only build, not the one now sitting on the server. The edge had refreshed what it said about the file, but it was still serving the cached body it already held.

Why HEAD and GET can disagree
It is tempting to assume HEAD is “GET without the body”, so if HEAD is right, GET must be right. That is how the HTTP spec describes it for an origin server. A CDN edge is not your origin server. It keeps its own copy of responses, keyed mostly on the URL, and how it handles HEAD for a cached object, revalidation, partial content and large files is an implementation detail of that CDN. Some edges forward HEAD to the origin, or answer it from fresher metadata, while still serving GET from a stored body until that object expires or is purged. Others cache them separately. You usually cannot see which from the outside.
So the lesson is not “this CDN has a bug”. It may well be documented, intended behaviour. The lesson is that the headers are a claim, and for a file people will install, you verify the bytes, not the claim.
The fix: a new filename, not a fresher cache
There were two ways out. One was to purge the CDN cache for that URL and wait for every edge to drop its copy. The other was to stop asking the CDN to forget anything, and give the new file a URL it had never seen.
We chose the second. The new zip went up as HappyTracker-macOS-universal.zip. A URL the edge has never cached cannot be served stale; the first request goes to the origin and gets the real bytes. Then we pointed the download configuration at it:
'mac' => [
'label' => 'macOS',
'note' => 'Apple silicon & Intel · macOS 12+',
'version' => '1.0.0',
'size' => '2.2 MB',
'enabled' => true,
'file' => env('DOWNLOAD_MAC_URL', $base.'/HappyTracker-macOS-universal.zip'),
],
That is the entry as it looked after the fix. The size string changed as well. It is shown next to the download button, and a page that says 1.7 MB for a 2.2 MB file is one more small thing that makes people wonder whether they got the right one.
The old zip and the old config entry were kept on the server with a dated .bak suffix, not deleted. If the new build had turned out to be broken on some Mac we had not tested, rolling back would have been a rename and one config line, not a rebuild.
This only worked cleanly because nobody links to the file directly. Every download button goes through one API route that records the click and then redirects:
public function download(Request $request, string $platform): RedirectResponse
{
$config = config("downloads.platforms.$platform");
abort_unless($config && $config['enabled'] && ! empty($config['file']), 404,
'That download is not available.');
DB::table('app_downloads')->insert([
'platform' => $platform,
'source' => in_array($request->query('source'), ['web', 'landing'], true)
? $request->query('source') : null,
'ip' => $request->ip(),
'user_agent' => substr((string) $request->userAgent(), 0, 500),
'user_id' => optional($request->user())->id,
'created_at' => now(),
]);
return redirect()->away($config['file']);
}
Because the public link is /api/v1/download/mac, not the zip’s URL, changing the filename did not break a single link anywhere: not on the website, not in old emails, not in the app. The route reads the current file location from config on every request. When the Mac link later moved again, to a download listing, it was the same one-line change in the same place, and every existing link kept working.
If your download buttons point straight at /downloads/app.zip, renaming the file means hunting down every link. That is exactly the pressure that makes people overwrite in place, and overwriting in place behind a CDN is the trap.
What the edge serves today
Weeks later, both names serve the same universal file. The old name was the one we had overwritten with the universal build that night; once the edge’s cached copy expired, it started serving those bytes too, which helps anyone with a bookmarked direct link. Here are the headers for the new name as they look today:
HTTP/2 200
content-length: 2263453
last-modified: Sun, 20 Sep 2026 19:03:38 GMT
etag: "22899d-6ab02e0a-457639c7484508e4;;;"
platform: hostinger
server: hcdn
x-hcdn-cache-status: MISS
x-hcdn-upstream-rt: 0.067
And the hashes on the server, compared with what a fresh download returns:
# on the server, over ssh: the truth
sha256sum public/downloads/HappyTracker-macOS*
8d8dcf9b...78359a4 HappyTracker-macOS-universal.zip
8d8dcf9b...78359a4 HappyTracker-macOS.zip
406aea25...1932704 HappyTracker-macOS.zip.bak-20260921-0031
A browser download of either name today hashes to 8d8dcf9b..., the universal build. That agreement is what “deployed” should mean for a downloadable file. On the night of the fix, the old name failed exactly this comparison while its headers looked correct.
Note the x-hcdn-cache-status: MISS in that output. That header is worth reading on every check. A MISS means this response came from the origin. A HIT means you are looking at the edge’s stored copy, and that copy may be older than the file on disk.
How we verify a download now
The check that would have caught this on the first try is short. It downloads the file the way a browser does, compares its hash with the hash of the file we built, and then looks inside the archive to confirm the binary really has both architectures:
#!/bin/sh
# verify-download.sh <public-url> <expected-sha256>
# Checks the bytes a browser would get, not what the headers claim.
set -eu
url="$1"; want="$2"
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
curl -sfL "$url" -o "$tmp/dl.zip"
got=$(shasum -a 256 "$tmp/dl.zip" | cut -d' ' -f1)
[ "$got" = "$want" ] || { echo "WRONG BYTES: got $got"; exit 1; }
cd "$tmp" && unzip -q dl.zip
bin=$(find . -path '*/Contents/MacOS/*' -type f ! -name '._*' | head -1)
lipo -archs "$bin" # expect: x86_64 arm64
file "$bin"
echo "OK: $url
A few details in that script came from mistakes.
It follows redirects (-L). If you test through the public download route instead of the raw file URL, which is better because it is what users click, curl needs to follow the redirect to reach the file.
It skips ._ files. Our zip contains AppleDouble files: small ._HappyTracker sidecars that macOS adds to keep extended attributes when an archive is made in certain ways. A naive find picked one of those first, and lipo failed with “can’t figure out the architecture type”. The archive was fine; the check was wrong. The sidecars are harmless on a Mac, but they are a sign to look at how you zip the app. ditto -c -k --keepParent is the usual tool for app bundles.
It runs lipo -archs and file on the binary inside the downloaded archive, not on the build output on the build machine. Our build output was correct the whole time. The bytes reaching users were not. Checking the build machine would have passed while the bug was live.
A cache-busting query string is for checking only. Adding ?x=12345 to a URL usually makes the edge treat it as a new object and fetch from the origin. That is useful to confirm the origin has the right file. It does not fix anything for users, who request the plain URL. If ?x= gives you the new file and the plain URL gives you the old one, you have just proved the edge is stale.

The rules we follow now
Never overwrite a downloadable file in place behind a CDN. Upload the new file under a new name and switch the pointer. Old name, old bytes, cached or not, stops mattering the moment nothing links to it.
Put the version or a distinguishing word in the filename. HappyTracker-macOS-universal.zip was enough for one fix. For a release process, HappyTracker-1.0.1-macOS.zip is better. The filename then changes on every release by design, and stale caches are impossible by construction rather than by care.
Keep one indirection between the button and the file. A route, a redirect, or a single config value. It is what makes renaming free, and it gives you a place to count downloads. We count in the database before redirecting, so our numbers do not depend on CDN logs.
Verify the GET body, not HEAD. Hash what a fresh download returns and compare it with the hash of the file you built. Size alone is weak: two different builds can be the same size, and two files of different sizes tell you something is wrong but not what.
Verify the contents, not the container. For a Mac app, unzip and run lipo -archs on the binary inside. For a Windows build, check the file type and version metadata of what downloaded. For a .deb, dpkg-deb -I the downloaded file. A correct zip of the wrong binary passes a hash check against itself.
Keep the previous file, renamed with a date. Rolling back should take one rename and one config edit, without a rebuild.
Update the visible size and the description in the same change. If the page says “Apple silicon & Intel”, the check above should prove both slices are there before anyone sees that text.
Why this is easy to miss
Most of what we deploy is HTML, CSS and JavaScript, and the frameworks we use already handle caching for those: bundles get content hashes in their filenames, so a new build means new URLs, and the CDN never has a chance to serve an old script. Downloads are usually the one class of file still managed by hand, uploaded by SFTP, with a fixed friendly name because a human will see it in their Downloads folder.
That combination, a fixed name, replaced by hand, rarely changed and long cache lifetimes, is exactly where an edge cache will catch you. It does not happen often enough to build a habit around, so it has to be a written rule.
There is also a quieter cost. A user who downloaded the broken file, saw “Bad CPU type” or an app that would not open, and gave up, never tells you. From the server’s point of view the download succeeded: a 200, the right number of bytes for what the edge held. Nothing in your logs says that person got last week’s file. The only defence is to check the bytes yourself, from outside, every time.
A short checklist for replacing any download
- Build, then record the SHA-256 of the exact file you are about to upload.
- Upload under a new filename that includes a version or distinguishing word.
- Point the single source of truth (route, config, redirect) at the new name. Update size and description text in the same change.
- Download through the public link, as a user would, and compare the hash.
- Look inside:
lipo -archs,fileor the platform equivalent on the downloaded copy. - Read the CDN cache-status header on the check. A HIT on a URL you just changed is a warning.
- Keep the previous file with a dated suffix until the new one has been in use for a while.
Questions
Wouldn’t purging the CDN cache have been enough?
Probably, eventually. But a purge depends on the provider’s panel or API, on every edge honouring it, and on you remembering to do it on every release. A new filename needs none of that. It is also easier to prove: a URL that has never been requested cannot have a stale copy anywhere.
Should downloads be served from behind a CDN at all?
Yes. A 70 MB installer is exactly what a CDN is good at. The answer is to treat the file as immutable once published, the same way your build tool treats hashed JavaScript bundles, not to remove the cache.
Is a HEAD request ever useful here?
It is fine for a quick “is this URL alive” check, and the cache-status header is worth reading. It is not evidence that users receive the file you uploaded.
How did we know the old body was being served if the headers looked new?
By downloading it and looking at what arrived instead of at the headers: the file was the old arm64-only build. That is why the check in this post hashes the body and runs lipo on the binary inside. Keeping a recorded hash of each build tells you at once which file people are getting.
Happy Tracker is our time tracking, leave and attendance system, with desktop apps for Windows, Mac and Ubuntu. See how it works.



