How do Cloudflare and CloudFront bill for CDN traffic?
This analysis is for backend and platform engineers who own CDN spend and need to predict how a bill will change, not just compare list prices. It compares two billing models that measure traffic in different ways.
CloudFront meters usage directly. Data transfer out to viewers is billed per GB, with rates that vary by the viewer's geographic region and fall as monthly volume increases. Requests are billed separately, per batch of requests, and the rate depends on region and on HTTP versus HTTPS. Edge compute, invalidations beyond the included allowance, and other features are additional meters on top.
Cloudflare generally does not meter standard CDN bandwidth on its plans. You pay a plan tier, and costs grow through add-on products such as edge compute, object storage, image handling, and routing features. Enterprise contracts are negotiated. Plan terms also limit what the standard CDN may serve, so check whether your content type is covered.
| Dimension | CloudFront | Cloudflare |
|---|---|---|
| Bandwidth to viewers | Per GB, by region and volume tier | Generally unmetered on CDN plans |
| Requests | Per-request charge | Included in plan; some add-ons bill per request |
| Main cost driver | Bytes, request count, geography | Plan tier, add-on usage, contract terms |
| Price discovery | Public rate card | Public plans; Enterprise negotiated |
Starting from the headline per-GB egress rate is misleading. On CloudFront, request charges can outweigh bandwidth costs for small API responses. On Cloudflare, the per-GB figure is close to zero, so the real cost depends on which add-ons your architecture requires.
Both providers change their pricing. Confirm current terms on each provider's pricing page before relying on any model.
Who should use this cost model?
This model fits engineers who have to make or defend a CDN decision with their own traffic data:
- Platform and infrastructure engineers who own the CDN configuration and are asked whether a move would lower the bill.
- Backend engineers running API-heavy services, where request counts, cache misses and per-request add-ons matter more than bandwidth.
- Teams with an AWS origin who are weighing a third-party CDN and need to account for origin egress that CloudFront would not bill.
- Engineering leads or FinOps practitioners who review CDN invoices and need to explain which line items move when traffic changes.
It is less useful if your traffic is small enough that the CDN bill is a rounding error, or if you are already on a negotiated enterprise contract with fixed pricing. In that case, the contract terms matter more than the formula. It is also not a latency or reliability comparison. Those need separate measurement from the regions your users are in.
Why does origin-to-CDN transfer change the comparison?
A CDN bill covers only the edge-to-user leg. Each request also has an origin-to-edge leg, and who pays for it depends on where the origin runs.
When the origin is in AWS, such as S3, an Application Load Balancer, or EC2, AWS does not normally charge data transfer from that origin to CloudFront. If you put a third-party CDN such as Cloudflare in front of the same origin, AWS treats every byte the CDN fetches as ordinary data transfer out to the internet and bills it at standard egress rates. Your edge bandwidth may become cheaper while the origin side becomes a new line item.
Cache misses determine the size of that line item. Every miss sends a request back to the origin, so origin egress scales with your miss rate. Each miss also uses origin compute: load balancer capacity, application CPU, and database reads that a cached response would have avoided.
Illustrative estimate. Assume 100 TB delivered per month and internet egress of $0.08/GB from the cloud provider.
- 95% cache hit ratio: 5 TB comes from origin, which costs about $400/month in origin egress.
- 60% cache hit ratio: 40 TB comes from origin, which costs about $3,200/month, plus the compute needed to serve those requests.
With a high hit ratio, origin egress stays small and the edge price drives the comparison. With a low hit ratio, which is common for personalized or uncacheable API responses, the egress you pay to AWS can cancel the bandwidth savings from leaving CloudFront.
PATH A: AWS origin behind CloudFront
+-------+ edge->user +------------+ origin->edge +----------------+
| Users |<-------------| CloudFront |<----------------| AWS origin |
+-------+ CDN bill +------------+ not billed | S3 / ALB / EC2 |
+----------------+
PATH B: same AWS origin behind Cloudflare
+-------+ edge->user +------------+ origin->edge +----------------+
| Users |<-------------| Cloudflare |<----------------| AWS origin |
+-------+ CDN bill +------------+ internet egress| S3 / ALB / EC2 |
billed per GB +-------+--------+
|
v
+----------------+
| compute per |
| miss: ALB, CPU,|
| DB reads |
+----------------+
Cache misses scale the origin leg (illustrative: 100 TB/mo, $0.08/GB)
hit ratio 95% --> 5 TB from origin --> ~$400/month egress
hit ratio 60% --> 40 TB from origin --> ~$3,200/month egress
+ origin compute
The CDN bill covers only the edge-to-user leg. With an AWS origin, the origin-to-edge leg is normally not billed for CloudFront but is billed as internet egress for a third-party CDN, and that cost grows with the cache miss rate (figures are an illustrative estimate).
Why do API traffic and static assets cost differently on a CDN?
That pattern explains why the two traffic shapes need separate models. Static assets move many bytes per request and are served mostly from cache, so the per-GB rate drives the bill. API responses are small, numerous and often uncacheable. For those, request fees, origin fetches and per-request add-ons such as WAF rules, bot filtering and edge functions make up most of the cost.
| Dimension | Static assets | API traffic |
|---|---|---|
| Bytes per request | High | Low |
| Typical cache hit ratio | High | Low to near zero |
| Dominant cost | Bandwidth (per GB) | Requests, origin fetches, security and compute add-ons |
| Main lever | Hit ratio, compression | Fewer billable requests, cheaper origin path |
Illustrative estimate (assumed numbers, not a benchmark). Assume $0.08/GB, $0.01 per 10,000 requests and $0.60 per million requests for a WAF add-on.
cost = GB × rate_GB + (requests ÷ 10,000) × rate_10k + (requests ÷ 1M) × rate_addon
- Assets: 10,000 GB and 20M requests come to $800 + $20 + $12, or $832. Bandwidth accounts for about 96% of the total.
- API: 250 GB and 50M requests come to $20 + $50 + $30, or $100. Bandwidth accounts for 20%.
Cutting the per-GB price on the API workload saves little. Raising the cache hit ratio changes the total more than list price does:
- Tiered or regional caching and origin shield send edge misses through one cache layer before they reach your origin. This reduces origin egress and load.
- Cache key normalization strips tracking parameters, sorts query strings and ignores irrelevant headers so that identical content maps to one cache key.
- Sensible TTLs keep fingerprinted assets cached for long periods. Shared, non-personalized API responses can still be cached for a few seconds.
The configuration example below applies key normalization and TTLs.
Resources:
StaticAssetsCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Name: static-assets-fingerprinted
MinTTL: 86400 # at least 1 day at the edge
DefaultTTL: 31536000 # 1 year when origin sends no Cache-Control
MaxTTL: 31536000
ParametersInCacheKeyAndForwardedToOrigin:
EnableAcceptEncodingGzip: true # one key per encoding, not per raw header value
EnableAcceptEncodingBrotli: true
HeadersConfig: { HeaderBehavior: none }
CookiesConfig: { CookieBehavior: none }
QueryStringsConfig:
QueryStringBehavior: none # file name carries the version hash
SharedApiCachePolicy:
Type: AWS::CloudFront::CachePolicy
Properties:
CachePolicyConfig:
Name: api-shared-short-ttl
MinTTL: 0 # honor origin no-store/private on personalized routes
DefaultTTL: 5 # cache shared responses for a few seconds
MaxTTL: 60
ParametersInCacheKeyAndForwardedToOrigin:
EnableAcceptEncodingGzip: true
EnableAcceptEncodingBrotli: true
HeadersConfig: { HeaderBehavior: none }
CookiesConfig: { CookieBehavior: none }
QueryStringsConfig:
QueryStringBehavior: whitelist # utm_*, fbclid etc. are dropped from the key
QueryStrings:
Items: [page, limit, category]
CloudFormation cache policies that normalize CloudFront cache keys by allowlisting only meaningful query strings and excluding cookies and headers, with long TTLs for fingerprinted assets and a few-second TTL for shared API responses.
How does the cost model work?
The model treats a CDN bill as the sum of a few independent meters. Each meter is either driven by your traffic or fixed by your plan:
- Delivery bandwidth. Bytes sent from the edge to users, multiplied by the per-GB rate for each billing region. On CloudFront this is a real meter. On Cloudflare CDN plans it is usually zero.
- Requests. Request count multiplied by the per-request rate. On API traffic this term often matters more than bandwidth.
- Origin egress. Bytes the CDN fetches from your origin on cache misses, which are
GB × (1 − hit_ratio), multiplied by your origin provider's egress rate. With an AWS origin behind CloudFront this rate is normally zero. Behind a third-party CDN, it is standard internet egress. - Fixed and add-on fees. Plan tiers, WAF, edge compute, logging, origin shield and support, as listed in the hidden line items section below.
Traffic inputs and rates are kept separate. Traffic comes from your logs and describes what your system does. Rates come from each provider's price page or quote and describe what the vendor charges. The same traffic is evaluated against each provider's rate table, and the totals are compared. Because API and asset traffic are modeled as separate classes, you can see which class and which meter drive the difference between providers, not only which total is lower.
The model is a first-order estimate. It ignores volume tier breakpoints unless you add them to the rate table, and it assumes your hit ratio stays the same after a migration. A different CDN's cache behavior, tiered caching and key handling can change that ratio. Treat hit ratio as an input to test with a range of values, not a constant.
How do you build a CDN cost model from your own traffic data?
Export one month of CDN logs or the billing report. Pull five inputs for each traffic class: bytes delivered, request count, the share of bytes in each billing region, cache hit ratio, and where the origin runs. Split API and asset traffic by path prefix or hostname. The two classes respond to different rate components: assets are dominated by bandwidth, and API traffic by request count and cache misses.
The script below takes these inputs plus a rate table you fill in from each provider's current price page. It applies one formula per provider:
cost = Σ_region(GB_region × rate_region) + (requests / 10,000) × request_rate + GB × (1 − hit_ratio) × origin_egress_rate + fixed_fees
Illustrative estimate (assumed numbers, not a benchmark).
Assumed traffic:
- Assets: 50,000 GB, 200M requests, 95% hit ratio.
- API: 5,000 GB, 1B requests, 20% hit ratio.
Placeholder rates (not real prices) and a single blended region:
- Provider A: $0.05/GB delivered, $0.01 per 10k requests, free origin transfer.
- Provider B: $2,000 flat plan, no per-GB or per-request delivery charge, $0.05/GB origin egress.
| Line item | Provider A | Provider B |
|---|---|---|
| Assets | $2,500 + $200 = $2,700 | 2,500 GB × $0.05 = $125 |
| API | $250 + $1,000 = $1,250 | 4,000 GB × $0.05 = $200 |
| Fixed fees | $0 | $2,000 |
| Total | $3,950 | $2,325 |
Origin egress under Provider B comes from cache misses: assets 50,000 × 0.05 = 2,500 GB, API 5,000 × 0.8 = 4,000 GB.
API misses make up most of Provider B's variable cost. That makes API hit ratio the input to verify first.
Keep the script and the log query in version control. When pricing changes, you update the rate table and rerun. When someone proposes moving the origin, adding a region, or caching API responses, you change one input and rerun. Each re-evaluation then takes minutes instead of a new spreadsheet exercise.
TRAFFIC = { # one month, from CDN logs or billing export
"assets": {"gb": 50_000, "requests": 200_000_000, "hit_ratio": 0.95,
"region_share": {"blended": 1.0}},
"api": {"gb": 5_000, "requests": 1_000_000_000, "hit_ratio": 0.20,
"region_share": {"blended": 1.0}},
}
RATES = {
"provider_a": {"gb_by_region": {"blended": 0.05}, "per_10k_req": 0.01,
"origin_egress_gb": 0.0, "fixed": 0.0},
"provider_b": {"gb_by_region": {"blended": 0.0}, "per_10k_req": 0.0,
"origin_egress_gb": 0.05, "fixed": 2_000.0},
}
def class_cost(t, r):
# Delivery bandwidth, split by billing region
delivery = sum(t["gb"] * share * r["gb_by_region"][region]
for region, share in t["region_share"].items())
requests = t["requests"] / 10_000 * r["per_10k_req"]
# Only cache misses pull bytes from the origin
origin = t["gb"] * (1 - t["hit_ratio"]) * r["origin_egress_gb"]
return delivery + requests + origin
for provider, r in RATES.items():
lines = {name: class_cost(t, r) for name, t in TRAFFIC.items()}
total = sum(lines.values()) + r["fixed"]
detail = ", ".join(f"{k}=${v:,.0f}" for k, v in lines.items())
print(f"{provider}: {detail}, fixed=${r['fixed']:,.0f}, total=${total:,.0f}")
A minimal Python cost model that applies the section's formula to API and asset traffic separately and reproduces the illustrative estimate using placeholder rates.
How can a cost model save engineering time?
The main saving is avoiding work that a model would have shown to be unnecessary. A CDN migration involves rewriting edge code, translating WAF rules, rebuilding cache configuration and reissuing certificates. If origin egress from cache misses cancels the edge savings, all of that work is wasted. Running the model first lets you rule out a move in an afternoon instead of discovering the problem on the first invoice after cutover.
It also saves time in these ways:
- It points to the input that matters. Splitting costs by traffic class and meter shows whether the bill depends on bandwidth, request count or hit ratio. Engineers can then work on the lever that changes the total, such as cache key normalization for API routes, instead of negotiating a lower per-GB rate that barely moves an API-heavy bill.
- It replaces one-off spreadsheets. A versioned script with a stored log query produces the same answer every time. When pricing changes or someone asks "what if", you edit one value and rerun it instead of rebuilding the analysis and re-checking someone else's formulas.
- It shortens review discussions. Because assumptions are explicit inputs, reviewers can question a specific number, such as the assumed post-migration hit ratio, rather than the whole conclusion.
- It supports cheaper fixes first. Vendor-neutral changes such as compression, longer
Cache-Controllifetimes on versioned assets, and an origin shield can be modeled as changes to bytes or hit ratio. If they close most of the gap, you avoid a migration and the ongoing maintenance of a second CDN configuration.
Include the engineering-time terms from the development cost formula in the next section in the same script, so that the comparison includes migration and maintenance hours alongside usage charges.
Which hidden line items belong in a Cloudflare vs CloudFront cost estimate?
For API-heavy workloads, bandwidth is often not the largest line on the invoice. Small JSON responses move few bytes but trigger per-request charges for security, compute, and logging. The table below lists the adjacent costs and shows whether each input comes from a list price or needs a quote.
| Line item | CloudFront | Cloudflare | Model input source |
|---|---|---|---|
| TLS / custom certificates | Default certs included; dedicated-IP custom SSL is a separate charge | Universal certs on plans; advanced or custom certs vary by plan | List price, unless on enterprise |
| WAF and bot rules | AWS WAF billed per web ACL, rule, and request | Bundled by plan tier; advanced bot features usually need a quote | Mixed |
| Edge compute | CloudFront Functions and Lambda@Edge, billed per invocation (plus duration for Lambda@Edge) | Workers, billed per request on paid plans | List price |
| Log delivery | Standard logs land in S3 and pay storage; real-time logs add streaming costs | Log export features depend on plan | List price for CloudFront; plan-dependent for Cloudflare |
| Origin shield / tiered cache | Origin Shield adds a per-request fee | Tiered caching options vary by plan | List price |
| Support | AWS support plans priced as a share of the account's spend | Support level tied to plan | List price, or quote on enterprise |
Regional pricing. Both providers charge more for traffic served in some regions. CloudFront price classes lower the cost by excluding expensive edge locations. Users in those regions are then served from a farther edge, so their latency rises. Weight your model by your actual geographic traffic mix rather than by a single blended rate.
Contracts. Enterprise agreements and committed-spend discounts can make published rates irrelevant. Treat list prices as an upper bound until you have a quote.
Development cost. Add engineering time to the estimate. This includes the migration itself, rewriting WAF rules and edge logic, and the ongoing maintenance of a second configuration surface. The formula:
total = Σ(usage × rate) + migration hours × loaded hourly cost + monthly maintenance hours × loaded hourly cost
When should you avoid switching CDNs to cut egress fees?
Switching rarely pays off when your origin sits in AWS and your cache hit ratio is low. Data transferred from AWS origins such as S3 or EC2 to CloudFront is not billed as internet egress. Put a different CDN in front, and every cache miss leaves AWS at standard internet transfer rates. With a hit ratio around 60%, as is common for personalized or uncacheable API responses, those origin pulls can cancel whatever you save on edge rates.
Check plan terms before moving large files. Video streaming and bulk downloads of non-web content such as installers, datasets or archives may fall under plan terms or acceptable-use provisions. Those provisions can limit this traffic or push it toward a separately priced product. If large files make up most of your bytes, read the terms before you build a model on the headline rate.
Latency-sensitive APIs need regional testing. If your users are concentrated in regions where one provider has fewer points of presence, a cheaper rate can cost you response time. The same applies on CloudFront when you choose a restricted price class to save money, because it excludes some edge locations. Measure p95 latency from those regions before deciding.
Lock-in is also an engineering cost:
- Edge compute code. Cloudflare Workers and Lambda@Edge or CloudFront Functions use different runtimes and APIs, so edge code has to be rewritten.
- WAF rules. Rule formats differ and must be translated and retested.
- Cache configuration. Cache keys, TTL behavior and purge workflows don't map one-to-one between providers.
- Certificates. ACM certificates can't be exported for use outside AWS, so you'll need a new issuance and renewal process.
Finally, don't model on a single month of traffic. Volume and request mix can change sharply with a launch or a shift in traffic patterns, and a model built before that change can point you to the wrong provider.
What are the alternatives to a single-CDN setup, and when does hybrid make sense?
You have three realistic options. Staying on CloudFront keeps everything inside one AWS bill and one IAM model. Moving to Cloudflare changes how bandwidth is priced, but you take on migration work and a new set of plan limits. A hybrid setup sends large static assets through one CDN and APIs through the other, so each traffic class lands where its cost driver is cheapest.
| Option | Cost lever | Operational cost |
|---|---|---|
| Stay on CloudFront | Origin-to-CDN transfer inside AWS, committed-use discounts | Lowest: one vendor, one set of logs |
| Move to Cloudflare | Bandwidth pricing model, plan tiers | Migration, new WAF and cache rules |
| Hybrid | Each traffic class priced separately | Two DNS paths, split metrics, two purge APIs |
Hybrid only pays off when the savings on the dominant traffic class are larger than the engineering time it costs every month. On-call now has twice as many failure points. A purge on one CDN won't clear stale content on the other. Tracing a slow request means joining logs that use different field names and timestamps.
Some optimizations lower cost no matter which vendor you pick:
- Compress responses. Smaller payloads cut egress on every byte.
- Use long
Cache-Controllifetimes with versioned asset filenames. Assets can stay cached for a long time without stale-content risk. - Enable tiered caching or an origin shield. Fewer cache misses reach your origin.
- Trim API response payloads. Less data per request means less to transfer.
Decision checklist
- Mostly cacheable, high-volume assets: model the Cloudflare and hybrid options first.
- Mostly uncacheable API traffic with an AWS origin: CloudFront is usually the default.
- Small team or thin on-call rotation: avoid hybrid.
- Re-run the model after launches, pricing changes, or a change in your cacheable share.
How OneEnv can help
Disclosure: OneEnv is the product behind this blog.
OneEnv (oneenv.io) is a workspace-based governance platform for the things services share — environment variables, database structure, API routes and validation rules. A change to a shared value is staged on a branch, reviewed once, and then every affected service explicitly approves or rejects it before it goes live, so you can see who a change touches before it ships instead of finding out in production.
Applied to cloudflare vs cloudfront cost, this is where it helps:
Saves time
- Every service that inherits a shared value is listed in one place, so nobody searches repos and chats to find out who is affected.
- One review per branch replaces coordinating each team separately; each service still keeps its own approve/reject.
- Changing a shared variable is one edit and one review instead of editing every service's
.envby hand.
Saves cost
- Fewer production incidents and rollbacks caused by a shared value, route or column changing under a consumer unannounced.
- Less duplicated configuration to maintain: one shared definition inherited by many services.
- A wrong or stale value is caught at review time by the services it affects, not by a failed deploy.
- OneEnv has a free plan (1 workspace, unlimited services and members, full governance), so trying it costs nothing.
These are qualitative benefits, not measured results — how much you save depends on how many services share the value.
Want to try it? Start at oneenv.io.