Performance
Shipping zstd compression at the edge
Browsers started asking for zstd this year. Here is how we added a third content encoding to 52 cities without tripling cache storage, and why dynamic responses benefit most.
For most of the last decade, the content-encoding story at the edge was simple: gzip for everyone, Brotli for browsers that announced it, and precompressed Brotli for the static assets that matter. When Chromium-based browsers and then Firefox started sending zstd in Accept-Encoding, we had to decide whether a third encoding was worth the complexity. After six months of measurement, the answer was yes, but not for the reason we expected.
Smaller files were not the point
For static assets that we can compress once in the background, maximum-level Brotli is still slightly smaller than maximum-level zstd. On our corpus of the 200,000 most requested JavaScript and CSS objects, Brotli 11 produced files 2.8% smaller than zstd 19. That gap is too small for anyone to notice, and it points the other way from what you might have read.
The real difference is on the request path. Roughly 31% of the compressible bytes we serve are dynamic: HTML pages with short TTLs, JSON from cached APIs, server-rendered fragments. Those responses are compressed on the fly, on the first miss, with a CPU budget measured in microseconds. At comparable ratios, zstd level 3 compresses about six times faster than Brotli 5 and decompresses roughly three times faster on the client.
| Encoder | Output size (of original) | Compress speed | Decompress speed |
|---|---|---|---|
| gzip -6 | 28.4% | 61 MB/s | 380 MB/s |
| Brotli 5 | 24.1% | 47 MB/s | 410 MB/s |
| Brotli 11 (precompressed) | 21.0% | 0.9 MB/s | 420 MB/s |
| zstd 3 | 25.9% | 290 MB/s | 1,250 MB/s |
| zstd 9 | 23.8% | 68 MB/s | 1,240 MB/s |
| zstd 19 (precompressed) | 21.6% | 2.1 MB/s | 1,180 MB/s |
Measured on one core of our current cache node CPU, median over a 2 GB sample of customer HTML, JSON and JavaScript.
Three encodings, one cache entry budget
The obvious implementation stores a separate object per encoding: identity, gzip, Brotli and zstd. That would roughly double the storage used by text objects, which compete with images and video for the same NVMe. Instead, each cached text object keeps one canonical encoded body plus a small amount of metadata, and we derive the rest lazily.
- The first encoding we store is whatever the first client accepted, preferring zstd, then Brotli, then gzip.
- Other encodings are created only when a request needs them, and only kept if that variant is requested again within ten minutes.
- Hot objects, those requested more than 50 times an hour in a location, are re-encoded in the background at zstd 19 and Brotli 11 by a low-priority worker pool.
The encoding class is part of the cache key, so a purge removes every variant at once. Because Vary: Accept-Encoding is normalised to four classes, the explosion of distinct header values that browsers actually send never reaches the cache.
$ curl -sI -H 'Accept-Encoding: zstd, br, gzip' \
https://www.example.com/assets/app.9f3c1e.js | grep -iE 'content-encoding|vary|cache-status'
content-encoding: zstd
vary: Accept-Encoding
cache-status: cachebz; hit; ttl=31487789Window sizes and the 8 MB rule
zstd can use very large match windows, and some encoders default to window sizes that make decoding expensive on low-memory devices. The HTTP specification for zstd content coding requires decoders to support windows of at least 8 MB, and we cap our encoder there on every level. During testing we found one embedded browser that failed on 16 MB windows with a generic network error, which is exactly the kind of bug that would have been impossible to debug from a customer ticket.
Configuration
zstd is enabled for every site on every plan, with no configuration needed. If you want to control the order or levels, the [compression] section accepts:
[compression]
algorithms = ["zstd", "br", "gzip"] # server preference order
dynamic = { zstd = 3, br = 5, gzip = 6 }
background = { zstd = 19, br = 11 } # re-encode hot objects off the request path
min_bytes = 1024
types = ["text/*", "application/javascript", "application/json", "image/svg+xml"]What changed in production
Since the rollout finished on 4 November, 41% of compressible responses are delivered with zstd. Edge CPU time spent on compression dropped by 23% for the same traffic, which we have reinvested in longer background re-encoding of hot objects. On the client side, real-user measurements show a 4–7 ms improvement in time to interactive for pages over 300 KB of JavaScript on mid-range Android phones, almost entirely from faster decompression.
None of this requires customers to change their origin. If your origin already sends compressed responses, we pass them through when the encoding matches the client, and decompress and re-encode when it does not. If you see anything unexpected, the cache-status and content-encoding headers tell the full story, and our support engineers are a reply away at support@cache.bz.