API egress cost: the arithmetic behind the invoice
Egress is the line item that surprises teams. Compute is easy to forecast, storage grows slowly, but transfer scales with success: the more people use the product, the larger the bill. The good news is that the cost is a product of four numbers you can measure and change.
The four levers
Monthly transfer in gigabytes equals calls per month multiplied by the bytes that leave your origin, divided by the size of a gigabyte. The bytes that leave origin are not the bytes in the response body: compressed size, header overhead and cache hit rate all intervene. Each lever moves the result independently, which is why a payload review usually finds more savings than a price negotiation.
| Lever | Typical change | Effect on cost |
|---|---|---|
| Response size | 24 KB → 8 KB | −67% |
| Compression | brotli at 20% of original | −80% of body bytes |
| CDN cache hit | 0% → 70% | −70% of response egress |
| Call volume | Polling 30 s → 300 s | −90% |
Compression is the cheapest win
JSON compresses extremely well because it repeats key names. gzip typically brings a JSON body to 20 to 30 percent of its original size, and brotli is usually a further five to fifteen percent smaller on text, especially for cached dictionaries. Both are free at the application layer, and both cost a little CPU. If you are not compressing API responses, that single change usually beats every architecture discussion.
Cache hit rate is a business decision
A response that does not vary per user can be cached at the edge, and every hit removes an origin response from the bill. The obstacle is rarely technology; it is deciding that a ten-second-old value is acceptable. For public catalogue data, pricing tables and documentation, it almost always is. For account balances it is not, and no amount of CDN tuning will change that.
Watching the bill without watching it daily
Track three things monthly: bytes per call, calls per active user, and cache hit rate. If bytes per call rises, a response grew. If calls per active user rises, a client started polling more often. If the hit rate falls, a cache key changed. Each has a different fix, and each is visible long before the invoice arrives.
Finally, remember that egress price is not one number. CDN transfer, object storage transfer, cross-region traffic and inter-zone traffic are billed differently. Put your own contract price into the calculator rather than the list price, and compare the result with last month's invoice to catch the difference early.
Budgeting before the invoice
A monthly egress forecast is simple once you have the four levers: expected calls, bytes per call, compression ratio and cache hit rate. Multiply, convert to gigabytes, and multiply by your contract price. The value of doing this on paper is that it forces the assumptions into the open, where a product decision about caching or payload size can be made before the architecture is fixed.
Two habits keep the forecast useful. First, forecast per feature rather than per service, because features grow at different rates and a single aggregate number hides which one is responsible. Second, review the forecast against the actual invoice every month and explain the gap; a persistent ten percent gap is a modelling error, a sudden fifty percent gap is an incident or a launch.
- Forecast at the peak quarter, not the current month.
- Track cost per active user as a unit metric.
- Re-check the cache hit rate after every schema change.
Open the calculators and put these numbers to work on your own API.
Open API BenchFrequently asked questions
Is it cheaper to serve from a CDN than from origin?
Usually yes for cacheable content: CDN egress is often cheaper per gigabyte than object storage or compute egress, and the origin serves far fewer bytes. For uncacheable per-user data the CDN adds a hop without removing origin transfer.
Does gzip or brotli cost more CPU than it saves?
For JSON APIs the CPU cost is negligible compared with the bandwidth saved. Brotli is slower to compress at the highest levels; level 5 is a good balance for dynamic API responses.
Why does my bill not match calls × response size?
Because response size is measured before compression and before cache hits, and because requests and headers also transfer bytes. Compare against compressed origin bytes, not against the JSON you see in a debugger.
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.