A bill that was all one line
On 3 December Google Cloud emailed us that we had used 50% of this month's budget. That stopped us. It was the start of the month, only two days into December, and nothing about our traffic felt different. How do you burn through half a month's budget in two days?
The billing page showed ₹3,489.59 spent over 1 to 2 December. The two days before had cost about ₹426, so this was a 718% jump. A normal day for us is a few hundred rupees.
The odd part was the breakdown. 100% of the cost sat on one SKU:
Cloud Run Network Internet Data Transfer Out, AsiaPacific to AsiaPacific
No compute, no database, no storage. Only data leaving Google's network, sent from our backend to someone's browser. This post is how we traced it to one button, and what we changed so it can't happen again.
Tracing it in three steps
1. Billing, grouped by SKU. Billing → Reports, filtered to the two days and grouped by SKU, narrowed it to Cloud Run internet egress. Our Cloud Run services have instance caps, so compute couldn't reach this amount in a day anyway. Something was sending a lot of bytes out.
2. Cloud Monitoring, per service. We pulled daily totals of run.googleapis.com/container/network/sent_bytes_count grouped by service, and storage.googleapis.com/network/sent_bytes_count grouped by bucket:
| Day (UTC) | Backend sent to the internet |
|---|---|
| 28 Nov | 12.8 GB |
| 29 Nov | 0.1 GB |
| 30 Nov | 14.7 GB |
| 1 Dec | 1.3 GB |
| 2 Dec | 337.1 GB |
The media bucket showed a matching jump in reads on 2 December, all ReadObject. So the backend was reading files from storage and passing them straight through to a user.
Billing days run on US Pacific time, so 2 December in UTC lands partly on 1 December on the bill. That's why the report said "1 to 2 Dec".
3. Request logs, filtered by response size. Cloud Run logs every request with its response size. One query in Logs Explorer listed every response over 50 MB:
resource.type="cloud_run_revision" AND httpRequest.responseSize>50000000The same from a terminal:
gcloud logging read 'resource.type="cloud_run_revision" AND httpRequest.responseSize>50000000' --freshness=7d --format="table(timestamp,httpRequest.responseSize,httpRequest.requestUrl)"That returned 15 responses for the week. Fourteen were the same endpoint: the admin "download all" zip for a booking's raw footage.
One zip, ten times
The booking had about 40 GB of original photos. On 2 December an admin clicked Download All for it. Here is what the logs showed over the next two and a half hours, all from the same browser:
| Time (UTC) | Sent | Duration |
|---|---|---|
| 06:29:20 | 36.6 GB | 22 min |
| 06:29:32 | 0.3 GB | 3 min |
| 06:29:48 | 36.6 GB | 22 min |
| 06:29:56 | 34.6 GB | 30 min, cut off |
| 06:29:57 | 33.6 GB | 30 min, cut off |
| 06:30:38 | 35.6 GB | 30 min, cut off |
| 06:38:33 | 39.9 GB | 17 min, complete |
| 06:40:23 | 39.9 GB | 16 min, complete |
| 08:54:42 | 0.5 GB | a 20 file selection |
| 08:55:12 | 39.9 GB | 15 min, complete |
| 08:55:38 | 39.3 GB | 30 min, cut off |
Eleven requests, 337 GB in total. The person got the full set three times; the rest were partial copies thrown away.
Nobody did anything careless here. The zip is built on the fly and streamed through the backend, and Cloud Run ends every request after 30 minutes. A 40 GB zip doesn't always finish in 30 minutes, so the browser ends up with a broken file. The natural reaction is to click again. Several clicks overlapped, which slowed each one down and made the cut-off more likely, which led to more clicks.
The same pattern showed up on a smaller scale on 28 November: a 6.4 GB zip downloaded twice, 30 seconds apart.
Since every request is tied to a login, the app's audit log showed who it was too. That turned out not to matter. It was a reasonable person using the button the way it invited them to.
Why the safety net wasn't there
We had already hit the "big zip through the API" problem once, in the download button that did nothing. After that, the bulk download hook got a rule: above 1 GB, skip the zip and give the browser one signed Cloud Storage link per file.
export const ZIP_MAX_BYTES = 1024 * 1024 * 1024; // 1 GBPer-file links go storage → disk directly. There is no server in the middle, no 30 minute limit, and one failed file can be retried on its own.
But the admin booking page passed alwaysZip: true, because the studio had asked for "one zip, whatever the size". Editors got the safe path. Admins got the one that could stream 40 GB through Cloud Run and get cut off halfway. The server had no limit of its own either, so nothing stopped it.
The fix
The rule moved to the server, where no page can skip it, and the admin page lost its exception.
A hard cap on the server. Before streaming a single byte, the zip endpoints add up the file sizes and refuse anything over 2 GB:
public static final long MAX_ZIP_BYTES = 2L * 1024 * 1024 * 1024;
public static void requireWithinLimit(long totalBytes) {
if (totalBytes > MAX_ZIP_BYTES) {
throw new IllegalArgumentException(String.format(
"This download is %.1f GB, too large for one zip (limit %d GB). "
+ "Download the files individually, or narrow it by folder, event or date.",
totalBytes / 1e9, MAX_ZIP_BYTES / (1024L * 1024 * 1024)));
}
}2 GB leaves headroom over the frontend's 1 GB, so the normal path never trips it. It applies to the raw footage and the deliverables zips, for admins and team members.
Headers on the first byte, not before. The old controllers set Content-Type: application/zip and Content-Disposition: attachment before calling the service. If the service then refused, the browser would save the JSON error as booking-42.zip. Now the response stream sets those headers only when the first byte is written:
private OutputStream out() throws IOException {
if (out == null) {
response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
out = response.getOutputStream();
}
return out;
}A refusal leaves the response untouched, so the normal error handler sends a proper 400 with the message.
No forced zip on the admin page. alwaysZip is gone. Admins get the same rule as everyone else: up to 1 GB as a zip, larger sets as separate files.
Ask before big downloads. Above 5 GB, the page shows the file count and size first, and says that large downloads are billed per GB and that a failed file can be retried on its own.
On 2 December, this would have been one 40 GB download, about ₹400, instead of ₹3,489.
What it doesn't fix
Per-file links remove the waste, not the price. Sending data out of Google costs about ₹10 per GB whether it leaves through Cloud Run or straight from Cloud Storage. A studio that hands 40 GB shoots to editors every week still pays for every one of them.
That's why we're moving photo and video storage to Cloudflare R2 next, which doesn't charge for downloads. Our 275 GB library costs about the same to store there, and the same 40 GB download costs nothing. That migration is the next post.
Takeaways
- Read the bill by SKU first. "Cloud Run is expensive" and "Cloud Run sent 337 GB to the internet" lead to very different fixes.
- Response size is in your request logs. One filter on
httpRequest.responseSizefound the exact requests in seconds. - A timeout is a retry button. Anything that can run longer than your platform's request limit will be clicked again, and every retry starts from zero.
- Put limits on the server. A rule only the frontend knows can be switched off by one page.
- Keep the billing alerts on, and add one closer to the cause. The 50% budget email is how we found out at all, but it only fires on the month's running total, so it arrived after the money was spent. A log-based alert on responses over 50 MB would have flagged the first 40 GB request within minutes.