A news site's traffic does not arrive evenly. A story breaks, a link lands on the front page of an aggregator or in a push notification, and in ten minutes a single article goes from a few hundred readers to a few hundred thousand, across several continents. The same pattern hits a shop on launch day and a sports site at kick-off. Images are most of the bytes on those pages, so they are what decides whether the page stays fast for everyone or falls over for the readers furthest from your servers.

This article explains how ZawCloud Images routes each reader to a nearby edge node, how it absorbs a spike without hammering your origin, and the tools that tell you afterwards what was served, to whom and from where.

Routing: the nearest node, decided by DNS

Your images are served from your platform hostname (https://a3f9c21b.zwcld.net) or your own domain, CNAMEd to us. Either way, the name is answered by our own authoritative nameserver, which returns the address of the edge node nearest the person asking.

"Nearest" is worked out from the location of the reader's DNS resolver or, when the resolver passes it on, the reader's own network (the EDNS client subnet). Large public resolvers serve users from many countries, and without the client subnet a reader in Warsaw using a resolver in Frankfurt would be routed by Frankfurt's location instead of their own. Only nodes that are currently sending heartbeats are considered.

DNS answers have a 60-second lifetime. That number is a trade-off, and it is worth understanding: it is how long a reader's resolver keeps using an answer. A shorter lifetime means faster recovery when a node goes away, and more DNS queries. Sixty seconds is the usual compromise, and it is why a node that fails stops receiving new readers within about a minute.

Absorbing a spike

The dangerous moment in a spike is not the millionth request for an image. It is the first thousand, arriving at the same time, before anything is cached. Several mechanisms on each node deal with that:

  • Concurrent misses collapse into one. When a thousand readers request the same new image at the same width in the same second, the node fetches and encodes it once. The other 999 requests wait for that result instead of each going to your origin.
  • A shared cache tier. Renditions are kept in each node's memory and in a shared tier behind it, so a node that has just started, or one that evicted an entry, can fetch the finished rendition instead of making it again.
  • Revalidation instead of re-download. When a cached rendition expires, the node asks your origin whether the file changed (If-None-Match / If-Modified-Since). An unchanged image costs your origin a 304 with no body.
  • Missing files are remembered briefly. A broken image on a front page is requested on every view. The node remembers an origin 404 for about 30 seconds, so it does not ask your server again on each of those views.
  • Transforms wait for a slot. Encoding is CPU-bound, so a node runs a bounded number at once and queues the rest rather than slowing every request down together.

On the reader's side, every rendition is sent with a long, immutable Cache-Control and an ETag. A reader who scrolls back up, or reopens the article, gets the image from their own browser cache.

Updating a picture mid-story

Breaking news gets corrected. When a photo is replaced at the same path, a purge by path removes every size and format of it at once, across the fleet. The console reports how many nodes it reached and says so plainly when a purge was only partial, and a cache.purged webhook carries the same counts, so you know whether every node confirmed it. For a newsroom CMS, the cleanest setup is a management token with only the purge scope, called by the CMS on publish. Better still, give a replaced photo a new path, and nothing needs purging at all.

Knowing what was served

After the spike come the questions. Which images carried the traffic? Who was linking to us? Which countries did it come from? Did anything fail? There are four layers of answer.

Analytics & Traffic

The console's Analytics & Traffic tab shows deliveries and bandwidth over time, with three top lists for today, the last 7 days or the last 30:

  • Top images, with every size and format of one image counted together, so you see "the hero of the election story" rather than twelve renditions of it.
  • Top referring sites, by host only. A referrer's path can carry a search query or a session id, so it is never stored. This is where you find out that an aggregator, or a site you have never heard of, sent a third of your traffic.
  • Top countries, from the reader's address, located on the node that served them.

Each list is ranked by bandwidth, with deliveries beside it, because a few huge images and many small ones are different problems.

Access logs

For anything the dashboard does not answer, the access logs have one line per request: what was delivered, what was refused and why, and what was answered with a 304. Download them from the dashboard a UTC day at a time, as compressed newline-delimited JSON, which loads directly into most log tools, a data warehouse or a few lines of a script. API keys and signatures are stripped from the logged URLs, because these are files people pass around.

Webhooks

Some things you want to know about as they happen rather than afterwards:

  • quota.warning at 90% of your monthly allowance and quota.exceeded at 100%. During a spike, that is the one to watch.
  • request.failed when a node refuses a request it can attribute to you, with the reason.
  • domain.unverified if your custom domain's DNS stops pointing at us.
  • cache.purged when a purge completes, including how many nodes confirmed it.

Every delivery is signed so your receiver can verify it came from us. The quota events are also emailed to the account owner, whether or not a webhook is registered.

Usage through the API

A management token with the read scope pulls usage into your own reporting, for example to compare the image bill with the page views it served.

Quotas that serve first

The worst outcome of a viral story would be images disappearing because a counter could not be read. Plan quotas are designed the other way round: when the node cannot be sure an account is over its allowance, it serves. Cache hits count as deliveries, because they use bandwidth, but the warning webhook and email give you time to change plan before a limit applies.

A checklist for traffic you cannot predict

  1. Serve images from your own domain, CNAMEd to us, so every reader is routed to a nearby node.
  2. Use a short list of widths, so a spike fills a few cache entries per image, not dozens.
  3. Make sure your origin sends ETag or Last-Modified, so revalidation is cheap.
  4. Give replaced photos new paths. Keep a purge-only token in the CMS for the rest.
  5. Register quota.warning and request.failed webhooks into the channel your on-call person reads.
  6. After each big story, look at top images and top referrers. They tell you what to optimise next.

For why the image share of a page matters this much, see Images are most of your page weight. For why a short list of widths keeps the cache effective, see Cache keys multiply faster than you think.