Compression is a trade we make without noticing: burn processor time to send fewer bytes. Whether it pays depends on which of the two is scarce.
Three algorithms cover most of it. gzip is decades old and everything speaks it. brotli compresses text smaller than gzip but is slow at its higher levels. zstd reaches much better ratios at near-gzip speed and tunes across a wide range, which makes it a sensible default for anything compressed per request.
When the cost is paid matters more than which algorithm won the benchmark. A JavaScript bundle is compressed once at build time, so it can afford maximum effort — brotli at its slowest setting, paid for once and enjoyed by every visitor afterwards. An API response is compressed on every request, so a slow algorithm adds latency to the very request it was meant to speed up.
And it can be a straight loss. On a fast internal network, or for a 5KB payload that compresses to 4KB, the CPU time costs more than the bytes saved.
Every optimisation is a trade between two resources. It only helps when we traded away the one we had to spare.
