JSON compression ratios you can plan with
Compression is the rare optimisation that costs almost nothing and pays immediately. Yet most capacity plans still use uncompressed payload sizes, which overstates both bandwidth and, sometimes, latency budgets. Here is what the ratios actually look like.
Why JSON compresses so well
JSON repeats itself. Key names appear in every object, field values often come from a small vocabulary, and numeric identifiers share prefixes. A general-purpose compressor finds those repetitions quickly, which is why a typical API response shrinks to a fifth or a quarter of its original size with gzip, and slightly less with brotli.
| Content | gzip | brotli | Note |
|---|---|---|---|
| Small JSON object (under 1 KB) | 70–90% | 60–85% | Headers dominate |
| Typical list response | 20–30% | 15–25% | Best case for both |
| Base64 binary in JSON | 75–85% | 70–80% | Already encoded |
| Random identifiers | 85–95% | 80–90% | Little repetition |
Measuring your own ratio
Do not trust a generic figure. Take a day of real responses, compress them at the level you intend to use, and divide. Two details matter: compress at the same level the server uses, because brotli at level 11 can look far better than what you will actually deploy, and measure the full response including the envelope, not only the items array.
Where compression hurts
Three cases deserve care. Responses under a few hundred bytes may grow after compression because of the container overhead, so most servers skip compressing them. Highly random payloads such as encrypted blobs or base64 images compress poorly and waste CPU. And compressing responses that are already compressed — a zipped export, a JPEG — achieves nothing.
There is also a security dimension. Compression plus reflection of attacker-controlled input can leak information through size differences, which is why sensitive cross-origin responses are sometimes served without compression. For ordinary JSON APIs the risk is low, but it should be a deliberate decision rather than a default.
Compression and the latency budget
Compression saves transfer time but costs CPU. On a fast internal network the CPU cost can exceed the saving, particularly at high compression levels. On mobile networks, where transfer time dominates, compression wins clearly. Pick the level by where your clients are, not by the benchmark that looks best on a desktop.
Finally, keep the uncompressed size for memory planning. A worker that parses a 24 KB response allocates 24 KB, not the 5 KB that crossed the wire. Compression reduces the bill and the wire time; it does not reduce parsing cost.
Configuration details that change the result
Three server settings decide whether your compression behaves as measured. The minimum length threshold, often a few hundred bytes, prevents small responses from growing. The compression level decides the CPU and size trade-off, and the content-type filter decides whether JSON is compressed at all — some defaults skip application/json while compressing text/html.
Also check the interaction with caching. A response compressed with gzip for one client and served to another that only accepts identity is a correctness bug, so Vary: Accept-Encoding is required whenever compression is negotiated. And when a CDN re-compresses on the fly, the ratio you measured at the origin may not be the ratio the client receives.
- Confirm application/json is in the compressed content types.
- Send Vary: Accept-Encoding on every compressible response.
- Use level 5 for dynamic responses and level 9 only for static assets built ahead of time.
A quick check you can automate
Add a synthetic check that requests a representative endpoint with and without Accept-Encoding: gzip, compares the byte counts, and alerts if the compressed response is larger than ninety percent of the original. That single check catches a broken filter, a proxy that strips the header, and a payload that quietly turned into base64, all of which otherwise surface only on the invoice.
Open the calculators and put these numbers to work on your own API.
Open API BenchFrequently asked questions
Is brotli always better than gzip?
For text at equal CPU budgets brotli is usually smaller, but browser support for brotli over plain HTTP is limited to HTTPS, and some intermediaries break it. Offer both and let the client choose through Accept-Encoding.
Should I compress request bodies too?
Only for large uploads. Compressing small request bodies rarely saves enough to justify the CPU, and some proxies handle compressed requests poorly.
Why did my response get bigger after compression?
Very small responses can grow because the compressed stream carries its own header. Servers usually skip compression below a few hundred bytes for exactly this reason.
Sources
Related guides
- Capacity planning with Little's LawTurn a target request rate and three latency percentiles into the concurrency, threads and instances an API actually needs.
- Tail latency: why P95 and P99 decide your timeoutAverages hide the requests that hurt. How to read percentiles, calculate what they cost, and set timeouts that do not cut off healthy traffic.
- Retry storms: how a 1% error becomes 300% loadRetries are new traffic. Calculate the amplification, recognise the cliff, and design retry budgets that fail politely.
- REST vs GraphQL: measuring the payload differenceOver-fetching, under-fetching and query text all show up in the bytes. A practical way to compare the transfer volume of both designs.