In an app I run, media files live in object storage and are served through redirects. The storage bill had an overage line I did not like. I assumed the cause was my own users watching video. The logs said otherwise.

Measure first

Before changing anything, I wanted to know what was actually being downloaded. My first guess was image frames: the app produces a lot of them, and many small requests can add up. So the first step was to check whether image frames dominated egress. They did not. That ruled out the most obvious fix and pointed me at video and audio files instead.

This step is easy to skip, and skipping it costs the most. If I had spent a week optimising image delivery I would have saved almost nothing.

What the numbers said

Over a day, uncached storage egress was 15.95 GB. Broken down by who was asking:

  • AI crawlers: 10.50 GB, about 66%. The biggest single source was one AI crawler user agent, meta-externalagent, which took 8.95 GB of video and 1.02 GB of audio. Amazonbot took 0.48 GB. Both are identified in their operators' own documentation: Meta's web crawlers page for meta-externalagent, and Amazon's Amazonbot page.
  • Unattributed: 5.46 GB. These are requests I could not attribute to a known crawler. They may be people, but I have not confirmed that.

Two-thirds of the bytes went to requests I could attribute to AI crawlers; the rest were unattributed, not confirmed customers.

A caution about reading these numbers: they come from one day of data, and "unattributed" only means the user agent did not match a crawler I knew. I treat the split as a strong signal, not a precise constant.

The fix

I did not want to block everything automated. Search engines send real visitors. Link previews make shared links look right. So the rule is narrow.

On the video file route, the rule I wrote is:

  • meta-externalagent and Amazonbot get 403 Forbidden.
  • Search engine bots (Googlebot and Googlebot-Video), the Facebook link-preview fetcher (facebookexternalhit), ordinary browsers, and requests with no user agent at all keep the normal redirect.

I also wrote groups for those two crawlers for robots.txt. That is the polite way to say no, and a well-behaved crawler may honour it. But robots.txt is advisory. Nothing enforces it. That is why the route returns 403 as well.

Two details I care about:

  • The user-agent check runs before any URL signing. A blocked crawler never receives a signed storage URL, so it cannot fetch the file even once, and I do not spend work generating a URL for it.
  • The 403 responses are no-store. A cache must not keep a block and hand it to a real visitor later.

An illustrative sketch of the ordering (not copied from the app):

// illustrative only
const BLOCKED_AGENTS = [/meta-externalagent/i, /amazonbot/i];

export async function GET(req: Request) {
  const ua = req.headers.get("user-agent") ?? "";

  if (BLOCKED_AGENTS.some((re) => re.test(ua))) {
    return new Response("Forbidden", {
      status: 403,
      headers: { "Cache-Control": "no-store" },
    });
  }

  const url = await signStorageUrl(/* file id */); // only reached by everyone else
  return Response.redirect(url, 302);
}

Allowing no-user-agent requests through was deliberate. Blocking them risks breaking legitimate tools, and nothing in my data pointed at them.

What it should save

The storage overage should shrink noticeably once the two largest sources are blocked. That is an expectation, not a measurement. I will measure it after a few weeks of data and update this article if the real number differs.

Update: the first fix made it worse

The next day's numbers did differ, in the wrong direction. Crawler video egress went from about 9 GB to about 15 GB a day. The block on the video route worked: the two crawlers got 403 there. But the watch pages themselves carried signed links to every scene's video and audio, so with the single video blocked, the crawlers fetched each scene instead.

The second fix applies the same rule one level up: the two crawlers now get 403 on the pages that embed media, and robots.txt disallows those paths too. Search engines, link previews and browsers still get the pages. Links signed before the change stay valid for up to seven days, so the real effect will take about a week to show. I will report that number here when I have it.

The lesson for the checklist: block the page that hands out the links, not only the file route. Otherwise you move the traffic instead of stopping it.

Limits

User agents are self-reported. A crawler that wants to evade a user-agent block can change its string, so this rule stops the two I identified and is not a general defence. If new offenders show up, the same measurement will find them. I would rather block what I can see in the data than guess at a long deny list.

A checklist you can run

  1. Get egress by user agent. Take your storage or CDN logs for a recent day and group bytes by user agent and by file type.
  2. Check your assumption. If you think images, or video, or downloads are the cost, confirm it before changing anything.
  3. Separate people from bots. Treat search engines, link-preview fetchers, and AI crawlers as different groups with different value to you.
  4. Decide per group. Allow, rate-limit, or block. Search and link previews usually earn their bandwidth.
  5. Add robots.txt rules, then enforce with a 403 for the ones that matter, since robots.txt alone is advisory.
  6. Check before you sign. Put the user-agent check ahead of URL signing or any expensive work.
  7. Mark block responses no-store.
  8. Estimate savings, then measure. Write the expectation down, and compare it against the next bill.

If you have run the same numbers on your own app, or want to challenge anything here, write to [email protected].

Helm & Proof